How do I install Docker Compose on CentOS 7?

How do I install Docker Compose on CentOS 7?

Docker Compose is a command-line tool for designing and configuring Docker applications with many containers. To put it another way, Docker Compose is a tool that allows you to link numerous containers and deploy an application from a single file. Docker Compose can be used in development, testing, environment setup, and CI (Continuous Integration) workflows.

For example, you’ll need one web server container (Apache/Nginx) and one database container (MySQL/MariaDB) to deploy a WordPress website inside a container. You may easily include numerous containers in the docker-compose file with Docker Compose. You can also add any other settings you require to make your app completely functional.

Steps for the installation Docker Compose

This article goes through how to install Docker Compose on an existing Docker host and how to use the docker-compose command to deploy containers. It’s expected that the Docker-enabled host is already up and running. Now we’ll go over how to install the Docker Compose Tool.

[[email protected] ~]# yum install epel-release -y
[[email protected] ~]# yum install python-pip -y
[[email protected] ~]# pip install docker-compose

For Docker Compose to run well, we recommend using the pip package manager version 6.0 or above. Run the following command to upgrade the pip version if it is less than 6.0:

[[email protected]~] # pip install --upgrade pip

Submit the following command to check Docker’s version:

[[email protected]~]# docker-compose --version
docker-compose version 1.25.4, build 8d51620a
[[email protected] ~]#

Using the Docker Compose tool to deploy containers

Make a directory, then a compose file inside of it. “docker-compose.yml” or “docker-compose.yaml” should be the filename. In the compose file, you’ll define the services for the apps and container images.

Download pictures of the WordPress and MySQL containers before you begin writing the compose file:

[[email protected] ~]# docker pull wordpress
[[email protected] ~]# docker pull mysql
[[email protected] ~]# docker image ls
wordpress latest d44c65e8e9a3 9 days ago 540MB
mysql latest 9b51d9275906 3 weeks ago 547MB

Then make a directory called “siteonwordpress” like follows:

[[email protected] ~]# mkdir siteonwordpress
[[email protected] ~]# cd siteonwordpress/
[[email protected] siteonwordpress]#

Make a docker-compose.yml file with the following contents:

version: '3.0'
image: wordpress
container_name: wp_cont
- 8080:80
- databaseserver:mysql
image: mysql:latest
container_name: wordpressdb_cont
001..docker compose

In the compose file above, two services named “frontserver” and “databaseserver” are defined. The container images are also supplied for them. The MySQL root and DB WordPress passwords are also mentioned, as are environment variables. According to the YAML syntax, indentation should be done with spaces.

Use the command to deploy your application, in this case a WordPress website:

[[email protected] siteonwordpress]# docker-compose up

From the directory where the docker-compose file is located, run “docker-compose up.”

The above command will create two containers named “wp cont” and “wordpressdb cont.” Use the following URL to get to your WordPress site:


To finish the WordPress installation, follow the directions on the screen. This indicates that the WordPress site was successfully deployed within the containers using the docker-compose command.

Let’s have a look at the “docker-compose” command’s parameters.

Provide a list of the containers that have been deployed for the application.

Run the following command to get the output:

[[email protected] siteonwordpress]# docker-compose ps
Name Command State Ports
wordpressdb_cont mysqld Up 3306/tcp, 33060/tcp
wp_cont apach ... Up>80/tcp
[[email protected] siteonwordpress]#

Containers and their services are stopped and started.

While running “docker-compose up,” press Ctrl+C or use the command below:

[[email protected] siteonwordpress]# docker-compose stop
Stopping wp_cont ... done
Stopping wordpressdb_cont ... done
[[email protected] siteonwordpress]#

To start the containers and their services, use the command “docker-compose start”:

[[email protected] siteonwordpress]# docker-compose start
Starting databaseserver ... done
Starting frontserver ... done
[[email protected] siteonwordpress]#

Look through the logs of containers

Run the command “docker-compose logs service-name” to browse all container logs or the logs of a specific container:

[[email protected] siteonwordpress]# docker-compose logs
[[email protected] siteonwordpress]# docker-compose logs databaseserver

Stop and destroy containers, as well as the network you’ve built

You may stop and delete containers with just one command using the “docker-compose down” command:

[[email protected] siteonwordpress]# docker-compose down
Stopping wp_cont ... done
Stopping wordpressdb_cont ... done
Removing wp_cont ... done
Removing wordpressdb_cont ... done
Removing network compose_default
[[email protected] siteonwordpress]#

Additional arguments can be found by running the command “docker-compose -help” in the help section.

Follow us TwitterFacebookLinkedIn

Open Source Listing

Previous Post
Next Post

Leave a Reply