Ubuntu Server Install Docker Compose

Docker compose is an useful tool for managing multiple docker containers. It helps us to launch, update and build a group of docker containers with single commands. In case of multi container application, docker compose helped us to manage it easier.

  1. See Full List On Docs.docker.com
  2. Command Line Reference

In this video I will install Docker Engine and docker-compose, also I will show how to connect to Ubuntu Server VM from Windows 10 using SSH and configure St. Also, be sure to install Docker Compose, as that is what we will be using to start running our containers: sudo apt install docker-compose Step 2 – Execute Docker Without Sudo. By default the docker rommand can only be ran by the root user, or a user in the docker group. Step 2 — Docker Compose Basics. With Docker Compose installed we can get to running our first container using it. We’ll use the well known Hello World example. To do this we’ll create our first Compose file. The Compose files are YAML files, and one of the default names that Docker Compose looks for is called `docker-compose.yml`. Moreover, the services can be defined in a “docker-compose.yml” file. If you are looking for a tool to run multiple isolated environments, Docker Compose is the industry standard and an excellent choice. In this guide, we will instruct you on how you can install, and setup Docker Compose on your machine running Ubuntu 20.04. First Steps in Ubuntu Server / Hardening and Config With Docker Start with this Install BashIt (Only if you do not use zsh or some similar console) Environments Unattended Upgrades Hardening SSH Over Firewalld Firewall UFW And IPTABLES Persistent Network Hardening Fail2Ban and PSAD Protect/Block TOR IPs Save IpTables Install Docker Install.

This tutorial helps you to install Docker compose on a Ubuntu 20.04 LTS Linux system.

Prerequisites

  • A system running Ubuntu 20.04.
  • Pre-installed Docker service on Ubuntu 20.04.
  • Terminal access with sudo privileged account.

Install Docker Compose on Ubuntu

Docker compose binary is available on official Github release. Use curl command line tool to download docker compose binary and place under the PATH environment to make it available globally.

First, make sure you have latest curl binary installed on your system.

Now, confirm the latest docker-compsoe binary version on Github releases page. At the time of this writing this tutorial, the current stable version is 1.29.2.

Reference

The following command will download the docker-compose binary version 1.29.2 and save this file at /usr/local/bin/docker-compose.

Make the binary docker-compose file executable

Verify the the docker-compose version by running the followign command.

Output:

See Full List On Docs.docker.com

Run a Docker Compose Example

At this stage Docker compose have been configured on your Ubuntu system.

  1. First of all, create a directory, which will contain all the files related to this example.
  2. Now, create a html directory. We will map this directory as document root of web server running under the Docker container
  3. Now create a index.html file under html file.
  4. Next, create the most important configuration file docker-compose.yml. This is the file contains all settings used by the docker-compose. Basis of this file docker-compose setup the images, network and containers etc.

    I will discuss this in parts for the better understanding. Edit file in a text editor:

    Add the following content to file.

    The above content shows that we are using latest version of docker compose version 3.

    Next, we defined a service “web” under sevices section. This will launch a docker container using pre-build “php:8.0-apache” AMI. The “html” directory in current folder will be mounted to containers /var/www/html directory.

    Keep your file in editing mode.

  5. Next add a MySQL database container in docker compose file.

    You can change the MySQL versions and access credentials. We have also updated web container configuration to link with database. This will allow web container to access database directly.

    Keep your file in editing mode…

  6. Optional but helpful to add phpmyadmin docker container. This will will help you to access database and its users.

    After adding the phpmyadmin, your docker-compose.yml look like below:

    Save you file and close it.

  7. Next, run the following command to pull all the images on your system.
  8. Next run the build command to create docker images. For this example, you can skip this command as we are using pre build images only.
  9. finally, run the docker-compose up command. Use “-d” option to deamonize container to keep running.
  10. The web server container is listening on port 8080, which we have bind with containers port 80. Access your host machine ip address on port 8080. You will see the index.html created under html directory.


    To make change just update html directory content and refresh page.

Conclusion

Command Line Reference

This tutorial helped you to install and use docker-compose on Ubuntu systems. The above instructions can be used on Ubuntu 16.04 LTS and above systems.