how to install and configure docker compose on ubuntu 20.04

How to Install and Configure Docker Compose on Ubuntu 20.04

Docker Compose is a command-line tool for managing multiple Docker containers. It is a tool for building isolated containers through the YAML file to modify your application’s services.

how to install docker compose on ubuntu 20.04

On the other hand, Ubuntu 20.04 feels more stable and easy to use, and as a result, users consider the operations running more smoothly, compared to some previous versions. Still, some users have issues while installing certain apps and software. Such is the case with Docker Compose.

In the following tutorial, we will show you how to install Docker Compose on Ubuntu 20.04 server.

Prerequisites

  • A fresh Ubuntu 20.04 VPS.
  • Access to the root user account (or access to an admin account with root privileges)

Step 1: Log in to the Server & Update the Server OS Packages

First, log in to your Ubuntu 20.04 server via SSH as the root user:

ssh root@IP_Address -p Port_number

You will need to replace ‘IP_Address‘ and ‘Port_number‘ with your server’s respective IP address and SSH port number. Additionally, replace ‘root‘ with the username of the admin account if necessary.

Before starting, you have to make sure that all Ubuntu 20.04 OS packages installed on the server are up to date. You can do this by running the following commands:

apt-get update -y

Step 2: Install  docker-compose on your server

By default, Docker Compose is available in the Ubuntu 20.04 default repository. You can install it with the following command:

apt-get install docker-compose

Once the Docker Compose is installed, verify the installed version with the following command:

docker-compose --version

You should get the following output:

docker-compose version 1.25.0, build unknown

This option will not guarantee that you downloading the latest docker-compose version.

On the GitHub repository, you will get the updates of Docker Compose, which might not be available on the standard Ubuntu repository. At the time of this writing this tutorial, the most current stable version is 1.29.2.

curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(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.

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

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

Once Docker Compose is installed, verify the installed version with the following command:

docker-compose --version

You should get the following output:

docker-compose version 1.29.2, build 5becea4c

Step 3: Test Docker Compose with Sample Container

Create a new directory for your sample container example:

mkdir test

Change directory that you just created:

cd test

From there, create a YAML configuration file:

nano docker-compose.yaml

And copy the following configuration into docker-compose.yaml file:

version: '3.3'
services:
   hello-world:
      image:
         hello-world:latest

Next, run the following command to pull the hello-world image on your system.

docker-compose up

The output should be similar to this:

Creating network "root_default" with the default driver
Pulling hello-world (hello-world:latest)...
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:9ade9cc2e26189a19c2e8854b9c8f1e14829b51c55a630ee675a5a9540ef6ccf
Status: Downloaded newer image for hello-world:latest
Creating root_hello-world_1 ... done
Attaching to root_hello-world_1
hello-world_1 |
hello-world_1 | Hello from Docker!
hello-world_1 | This message shows that your installation appears to be working correctly.
hello-world_1 |
hello-world_1 | To generate this message, Docker took the following steps:
hello-world_1 | 1. The Docker client contacted the Docker daemon.
hello-world_1 | 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
hello-world_1 | (amd64)
hello-world_1 | 3. The Docker daemon created a new container from that image which runs the
hello-world_1 | executable that produces the output you are currently reading.
hello-world_1 | 4. The Docker daemon streamed that output to the Docker client, which sent it
hello-world_1 | to your terminal.
hello-world_1 |
hello-world_1 | To try something more ambitious, you can run an Ubuntu container with:
hello-world_1 | $ docker run -it ubuntu bash
hello-world_1 |
hello-world_1 | Share images, automate workflows, and more with a free Docker ID:
hello-world_1 | https://hub.docker.com/
hello-world_1 |
hello-world_1 | For more examples and ideas, visit:
hello-world_1 | https://docs.docker.com/get-started/
hello-world_1 |
root_hello-world_1 exited with code 0

After downloading the image, Docker Compose creates a container and runs the hello-world program.

If you want to see the container information, you can use the following command:

docker ps -a

The output should be similar to this:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
31b0b7a2e9f0 hello-world:latest "/hello" 17 minutes ago Exited (0) 17 minutes ago root_hello-world_1

In this tutorial, we learned how to install Docker Compose on your Ubuntu 20.04 server, as well as the basics of how to use it.

Of course, you don’t need to do any of this if your server is covered by our Managed Linux Support services in which case you can simply ask our expert Linux admins to install Docker Composer onto your Ubuntu 20.04 server for you. They are available 24×7 and will take care of your request immediately.

installing docker compose on ubuntu 20.04

PS. If you liked this post, please share it with your friends on the social networks using the buttons below, or simply leave a comment in the comment section. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *