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:

version: '3.7'
services:
web:
image: nginx:alpine
ports:
- "8000:80"
volumes:
- ./app:/usr/share/nginx/html

Step 3 — Running Docker Compose

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

References:

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay