Share your love
Comprehensive Steps To Install Docker Compose on Centos 7
This article will show you how to Install Docker Compose on Centos 7 Step by Step. Docker Compose is a tool that is used to create and share multiple containers in a YML file. You can easily follow the instructions below on the Orcacore website to set up your Docker Compose in the latest version by downloading it from GitHub.
Table of Contents
How To Install Docker Compose on Centos 7?
To complete this guide on using Docker Compose Commands, 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
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 commands are 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 use the docker compose commands. And test your installation by creating a sample hello word YML file. By using Docker Compose you can create and share multiple containers in a YML file.
Hope you enjoy it. You may also interested in these articles:
Install ionCube PHP Loader on Rocky Linux 9