How To Install Docker Compose on Centos 7

This article will show you to Install Docker Compose on Centos 7 Step by Step. Docker Compose is a tool that is used to create and share multi containers in a YML file.

You can easily follow the instructions below to set up your Docker Compose in the latest version by downloading it from GitHub.

How To Install Docker Compose on Centos 7?

To complete this guide, you must have access to your server as a root or non-root user with sudo privileges. You can find an initial Centos setup by visiting this guide on Initial Server Setup with Centos 7.

Also, you need to have Docker installed on your server. To do this, you can follow this guide on How to Install and Use Docker on Centos 7.

When you are done, proceed to the following steps to complete your Docker Compose installation.

Setp 1 – Verify Docker Installation on Centos 7

First, you can verify your Docker installation by checking its version:

docker --version
Output
Docker version 24.0.1, build 6802122

Step 2 – Download Docker Compose Binary Package

At this point, you need to visit the GitHub Docker Compose release page and use the curl command to get the latest binary package under /usr/local/bin/ directory:

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

Now you need to set the correct permissions for your Docker compose directory on Centos 7 with the following command:

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

Step 3 – Verify Docker Compose Installation on Centos 7

Next, you can check your Docker compose installation by checking its version:

sudo docker compose version
Output
Docker Compose version v2.18.1

Step 4 – How To Use Docker Compose?

To see that Docker Compose is working correctly, we want to test it with a sample Docker container on Centos 7.

First, create a new directory for setting up the docker-compose file with the command below:

mkdir compose-test

Switch to your directory with the command below:

cd compose-test

Then, you need to create a docker-compose.yml file. This is a configuration file where you can define your container’s information.

To create the file, you can use the following command or use your favorite text editor, here we use the vi editor:

sudo vi docker-compose.yml

Add the following basic hello-world container based on the latest hello-world image:

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

When you are done, save and close the file.

Docker Compose Up Command

Next, launch the container within the ‘compose-test’ directory:

sudo docker compose up
Output
 [+] Running 2/2
 ✔ hello-world 1 layers [⣿]      0B/0B      Pulled                         2.6s
   ✔ 719385e32844 Pull complete                                            0.5s
[+] Building 0.0s (0/0)
[+] Running 2/2
 ✔ Network compose-test_default          Created                           0.1s
 ✔ Container compose-test-hello-world-1  Created                           0.1s
Attaching to compose-test-hello-world-1
compose-test-hello-world-1  |
compose-test-hello-world-1  | Hello from Docker!
compose-test-hello-world-1  | This message shows that your installation appears to be working correctly.
...

From the output, you should see that your Docker compose is working correctly on Centos 7.

Step 5 – Uninstall or Remove Docker Compose

To uninstall the Docker Compose from your system, first, remove the docker-compose binary package by using the following command:

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

Uninstall the Docker Compose software by running this command:

sudo yum remove docker-compose

Finally, uninstall all unwanted software dependencies by typing the following command:

sudo yum autoremove

Conclusion

At this point, you have learned to Install Docker Compose on Centos 7 in the latest version. And test your installation by creating a sample hello word YML file. By using Docker Compose you can create and share multi containers in a YML file.

Hope you enjoy it. You may be interested in these articles on the orcacore website:

Install ionCube PHP Loader on Rocky Linux 9

How To Set up Grafana on Rocky Linux 9

How To Install OpenJDK 17 on Debian 11

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!