How to setup Docker-Compose in Ubuntu 20.04

Docker Compose is an open-supply field device for running a multi-field Docker utility. Docker Compose makes use of a YAML syntax structure, this is normally used for configuration documents and to outline and run fieldprimarily based totally applications. Compose additionally guide to outline and configure utility‘s offerings in YAML format. The principal benefit of Docker Compose is that you could outline a multi-field utility in one single file, in an effort to spin up the utility with only a single command which does want to be finished to get it jogging. With Compose you could control the entire lifecycle of utility: Managing offerings with start, stop, or rebuild View the popularity of running services Output the log of running services Run a one-off command on a service In this tutorial, we discover ways to set up Docker-compose on Ubuntu 20.04, and a way to run the sample-container app.

Install Docker Compose on Ubuntu

For successful installation of Docker Compose, need to have Docker installed on Ubuntu 20.04.

Read Now: How to setup Docker in Ubuntu 20.04

After installing Docker, you can verify that docker is installed and version with following command:

$ docker version


Client: Docker Engine - Community
  Version:           20.10.6
  API version:       1.41
  Go version:        go1.13.15
  Git commit:        370c289
  Built:             Fri Apr  9 22:47:17 2021
  OS/Arch:           linux/amd64
  Context:           default
  Experimental:      true
 Server: Docker Engine - Community
   Version:          20.10.6
   API version:      1.41 (minimum version 1.12)
   Go version:       go1.13.15
   Git commit:       8728dd2
   Built:            Fri Apr  9 22:45:28 2021
   OS/Arch:          linux/amd64
   Experimental:     false
   Version:          1.4.4
   GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e
   Version:          1.0.0-rc93
   GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec
   Version:          0.19.0
   GitCommit:        de40ad0

Since we now have a Docker, we are ready to install Docker compose.

To install docker compose from the Official Ubuntu repository, run:

$ sudo apt install docker-compose
This option will not guarantee that you downloading the latest docker-compose version.

Instead of downloading Docker Compose from the Ubuntu repository, we are suggesting downloading the binary package using an URL with the curl command:

$ sudo curl -L "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

This command saves the file in: /usr/local/bin directory, under the name docker-compose.


% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                  Dload  Upload   Total   Spent    Left  Speed
100       633   100      633    0     0     5456      0 --:--:-- --:--:-- --:--:--   5456
100  12.1M   100  12.1M    0     0  40.0M      0 --:--:-- --:--:-- --:--:-- 40.0M

Next, we need to change the file permission, making the downloaded file executable with the following command:

$ sudo chmod +x /usr/local/bin/docker-compose

Verify installation, and check Docker Compose version:

$ docker–compose –version


docker-compose version 1.29.2, build 5becea4c

Test Docker Compose with Sample Container

Create new directory for your sample container example:

$ mkdir docker-compose-test

Change directory that you just created:

$ cd docker-compose-test

From there, create a YAML configuration file:

$ sudo nano docker-compose.yaml

And copy the following configuration into docker-compose.yaml file that you just opened:

version: '2' 
          image: ubuntu
          command: [/bin/echo, 'Hello world']

Save this, and run:

$ docker-compose up 

You need to see steps for:

  • pulling hello_world(ubuntu)
  • Downloaded picture for ubuntu:latest
  • Creating docker-compose-test_hello_world_1
  • Attaching to docker-compose-test_hello_world_1
  • Docker-compose the use of folder call because the venture call to prefix boxes and networks.

This created the box from the ubuntu picture, and run instructions that have been particular at the docker-compose.yaml.


In this tutorial, we discovered the way to deployation Docker-compose on Ubuntu 20.04, and the way to run the sample-box app. Docker-compose permits you to run more than one docker boxes on only a unmarried host, in case you want to run more than one boxes on more than one nodes, please check with answers which include Kubernetes or Swarm.


docker compose, docker compose up, installing docker compose, docker compose command, docker compose file, dockercompose yml, docker compose example, docker compose env file, docker compose environment, docker compose env, docker compose ubuntu, docker compose network_mode