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.

[root@dockerserver ~]# yum install epel-release -y
[root@dockerserver ~]# yum install python-pip -y
[root@dockerserver ~]# 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:

[root@dockerserver~] # pip install --upgrade pip

Submit the following command to check Docker’s version:

[root@dockerserver~]# docker-compose --version
docker-compose version 1.25.4, build 8d51620a
[root@dockerserver ~]#

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:

[root@dockerserver ~]# docker pull wordpress
[root@dockerserver ~]# docker pull mysql
[root@dockerserver ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
wordpress latest d44c65e8e9a3 9 days ago 540MB
mysql latest 9b51d9275906 3 weeks ago 547MB

Then make a directory called “siteonwordpress” like follows:

[root@dockerserver ~]# mkdir siteonwordpress
[root@dockerserver ~]# cd siteonwordpress/
[root@dockerserver siteonwordpress]#

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


version: '3.0'
services:
frontserver:
image: wordpress
container_name: wp_cont
ports:
- 8080:80
links:
- databaseserver:mysql
environment:
WORDPRESS_DB_PASSWORD: erf6UiwkzjTH
databaseserver:
image: mysql:latest
container_name: wordpressdb_cont
environment:
MYSQL_ROOT_PASSWORD: erf6UiwkzjTH
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:

[root@docker-host 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:

http://{dockerserver-ip}:8080

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:

[root@dockerserver siteonwordpress]# docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------
wordpressdb_cont docker-entrypoint.sh mysqld Up 3306/tcp, 33060/tcp
wp_cont docker-entrypoint.sh apach ... Up 0.0.0.0:8080->80/tcp
[root@dockerserver siteonwordpress]#

Containers and their services are stopped and started.

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

[root@dockerserver siteonwordpress]# docker-compose stop
Stopping wp_cont ... done
Stopping wordpressdb_cont ... done
[root@dockerserver siteonwordpress]#

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

[root@dockerserver siteonwordpress]# docker-compose start
Starting databaseserver ... done
Starting frontserver ... done
[root@dockerserver 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:

[root@dockerserver siteonwordpress]# docker-compose logs
[root@dockerserver 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:

[root@dockerserver siteonwordpress]# docker-compose down
Stopping wp_cont ... done
Stopping wordpressdb_cont ... done
Removing wp_cont ... done
Removing wordpressdb_cont ... done
Removing network compose_default
[root@dockerserver 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

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