DEV Community

Lam
Lam

Posted on

How To Install and Use Docker Compose on Ubuntu 20.04

Step 1 — Installing Docker Compose

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Enter fullscreen mode Exit fullscreen mode

Next, set the correct permissions so that the docker-compose command is executable:

sudo chmod +x /usr/local/bin/docker-compose
Enter fullscreen mode Exit fullscreen mode

To verify that the installation was successful, you can run:

docker-compose --version
Enter fullscreen mode Exit fullscreen mode

You’ll see output similar to this:

Output
docker-compose version 1.29.2, build 5becea4c
Enter fullscreen mode Exit fullscreen mode

Step 2 — Setting Up a docker-compose.yml File

Start off by creating a new directory in your home folder, and then moving into it:

mkdir ~/compose-demo
cd ~/compose-demo
Enter fullscreen mode Exit fullscreen mode

In this directory, set up an application folder to serve as the document root for your Nginx environment:

mkdir app
Enter fullscreen mode Exit fullscreen mode

Next, create the docker-compose.yml file:

nano docker-compose.yml
Enter fullscreen mode Exit fullscreen mode

Insert the following content in your docker-compose.yml file:

Step 3 — Running Docker Compose

docker-compose up -d
Enter fullscreen mode Exit fullscreen mode

References:

Top comments (0)