Install Docker Compose on Ubuntu 20.04 - Step by step process to perform it ?

Docker Compose is known as a command-line tool for running multiple containers on Docker defined. It uses the compose file in YAML format to configure the necessary resources for containers such as volumes, networking, and so on.

You can use Docker compose to define an isolated environment for containerized applications that can be run on any system.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform Ubuntu related installation and configuration queries.

In this context, we shall look into how to install Docker Compose on Ubuntu 20.04 LTS and explore some simple examples of using Docker Compose as well.


How to install Docker Compose on Ubuntu ?

Before installing Docker Compose, you have to install Docker on your Ubuntu 20.04 machine first.

i. Updating the packages repository and installing the dependent packages by running:

$ sudo apt update
$ sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

ii. Then, adding the Docker apt-repository to your OS:

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

iii. Once the Docker repository was added, you can install the Docker by running:

$ sudo apt update
$ sudo apt install docker-ce

iv. Verifying that Docker was successfully installed and started automatically:

$ sudo systemctl status docker

v. Next, let's see how to install Docker Compose.

At the time of this writing, the latest version of Docker Compose is 1.27.4.

To download the docker-compose file to your Ubuntu 20.04 machine, running:

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

vi. Then, grant the execute permission for docker-compose file:

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

vii. Verifying that the Docker Compose was successfully installed:

$ docker-compose --version


An Example to test Docker Compose on Ubuntu

Here, we're going to build an Nginx web server using Docker Compose:

i. First, create a new folder called myapp then change directory to it:

$ mkdir myapp
$ cd myapp

ii. Then, using your favorite editor to create a compose file called docker-compose.yaml

$ vim docker-compose.yaml
version: '3'
services:
webserver:
image: nginx:alpine
container_name: web_server
restart: unless-stopped
ports:
- "80:80"
- "443:443"
networks:
- app-network
networks:
app-network:
driver: bridge

In this compose file, we defined one service: webserver. It used docker image nginx:alpine from Docker Hub.

iii. In myapp directory, run the following command to start the application:

$ sudo docker-compose up

iv. Open new terminal and using curl command to verify that webserver is running:

$ curl localhost:80

v. To list the running service, run:

$ sudo docker-compose ps


[Need urgent assistance in fixing Docker related errors? We are available to help you today. ]

This article covers how to install and run Docker Compose on your Ubuntu 20.04 LTS machine. Docker Compose is yet another useful Docker tool. It allows users to launch, execute, communicate, and close containers with a single coordinated command. Essentially, Docker Compose is used for defining and running multi-container Docker applications.


To Install Docker Compose on Ubuntu:

1. Start by updating the default repository to ensure you download the latest Docker Compose:

$ sudo apt update

2. Then, upgrade the system to ensure all local packages and programs are up to date:

$ sudo apt upgrade

3. Then install Docker Compose from the Ubuntu repository by running:

$ sudo apt install docker-compose


To install Install curl on Ubuntu:

To download the binary package using an URL, you need curl. You can check whether you have this command-line utility by typing in the terminal window:

$curl

If the output displays "try 'curl --help' or 'curl --manual' for more information", move on to the next step. 

This message means curl is installed.

However, if the terminal says "command not found", you need to install curl with:

$ sudo apt install curl


To Check Docker Compose Version on Ubuntu:

To verify the installation, check the Docker Compose version by running:

$ docker–compose –version


To uninstall Docker Compose on Ubuntu:

Uninstalling Docker Compose from your Ubuntu system is a simple 3-step process.

1. Delete the Binary

First, delete the binary with the command:

$ sudo rm /usr/local/bin/docker-compose

2. Uninstall the Package

Then, use the apt remove command to uninstall the software:

$ sudo apt remove docker-compose

3. Remove Software Dependencies

Finally, remove the unwanted software dependencies by running:

$ sudo apt autoremove

Related Posts