Black Friday 2023 at Serverspace. 50% cash back on Cloud Servers
April 8, 2020
Updated August 1, 2023

How to install Docker Compose on CentOS 7

CentOS Docker FAQ

Using another OS?

Select the desired version or distribution.

Docker Compose is a command-line tool for defining and configuring multi-container Docker applications. In other words, Docker Compose is used to link multiple containers and deploy an application from a single file. The Docker Compose tool can be used in the development, testing, environment preparation, and CI (Continuous Integration) workflow.

In the Serverspace you can create a server with already installed app "Docker".

For example, you need to deploy a WordPress website inside a container, and it requires one web server container (Apache/Nginx) and one database container (MySQL/MariaDB). With Docker Compose, you can easily include multiple containers in the docker-compose file. You can also add any other configuration you need to make your application fully functional.

This tutorial reviews installing Docker Compose on an existing host containing Docker and touches on deploying containers with the docker-compose command.

It is assumed that the host with Docker is already set up and running. Let's move on to the steps of installing the Docker Compose Tool.

The steps of installing Docker Compose

Run this commands on your server

sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=|baseurl=|g' /etc/yum.repos.d/CentOS-*
yum -y install java

And now run the commands listed below in the same order:

yum install epel-release -y
yum install python-pip -y
pip install docker-compose


We recommend using the pip version 6.0 or higher package manager for the stable operation of Docker Compose. If the pip version is lower than 6.0, run the following command to update it:

pip install --upgrade pip

Check the version of Docker by submitting the following command:

docker-compose --version


docker-compose version 1.25.4, build 8d51620a

Deploying containers with the Docker Compose tool

Create a directory, then create a compose file in it. Name the file "docker-compose.yml" or "docker-compose.yaml". You will define the services for the applications and the container images in the compose file.

Before you start creating the compose file, download images of the WordPress and MySQL containers:

docker pull wordpress
docker pull mysql
docker image ls
wordpress latest d44c65e8e9a3 9 days ago 540MB
mysql latest 9b51d9275906 3 weeks ago 547MB

Then create a directory named "siteonwordpress":

mkdir siteonwordpress
cd siteonwordpress/

Create a docker-compose.yml file with the contents listed:

version: '3.0'
image: wordpress
container_name: wp_cont
- 8080:80
- databaseserver:mysql
image: mysql:latest
container_name: wordpressdb_cont

Two services named "frontserver" and "databaseserver" are defined in the compose file above. For them, the container images are also specified. Environment variables are defined, and the MySQL root and DB WordPress passwords are also mentioned. Note that you should use spaces for indentation, according to the YAML markup.

Deploy your application, in this case, a WordPress website, using the command:

docker-compose up


You should run "docker-compose up" from the directory where the docker-compose file is located.

The command above will deploy two containers named "wp_cont" and "wordpressdb_cont". Try accessing your WordPress website using the following URL:


Follow the instructions on the screen to complete the WordPress installation. This confirms that the WordPress site has been successfully deployed inside the containers by using the docker-compose utility.

Let's look at the parameters of the "docker-compose" command.

Output the containers deployed for the application

To output run the following command:

docker-compose ps
Name Command State Ports
wordpressdb_cont mysqld Up 3306/tcp, 33060/tcp
wp_cont apach ... Up>80/tcp

Stopping and starting containers and their services

Press Ctrl+C while running "docker-compose up" or run the command below:

docker-compose stop
Stopping wp_cont ... done
Stopping wordpressdb_cont ... done

Run the command "docker-compose start" to run the containers and their services:

docker-compose start
Starting databaseserver ... done
Starting frontserver ... done

Browse container logs

To browse the all container logs or the logs of a particular container, run the command "docker-compose logs {service-name}":

docker-compose logs
docker-compose logs databaseserver

Stop and delete containers along with the created network

With the "docker-compose down" command, you can stop and delete containers with just one command:

docker-compose down
Stopping wp_cont ... done
Stopping wordpressdb_cont ... done
Removing wp_cont ... done
Removing wordpressdb_cont ... done
Removing network compose_default

Additional parameters you can find in the help section by running the command "docker-compose -help".

5 out of 5
Аverage rating : 5
Rated by: 1
1101 CT Amsterdam The Netherlands, Herikerbergweg 292
+31 20 262-58-98
700 300
700 300
We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.