How to Setup Docker & Docker Compose on CentOS

Zenesys Technosys
5 min readOct 14, 2021

In this blog post, We will understand docker and how to install docker and docker-compose on CentOS operating system.

Table of Contents

● What is Docker?
● What is Docker Containers?
● Features of Docker
● What is Docker Compose?
● Docker Engine
● Installing Docker Packages on CentOS
● Installing Docker Compose on CentOS

What is Docker?

Docker is an open-source platform for developing, shipping, and running applications.


Docker uses Containers on the Host operating system to run the applications.

Containers ensure that the application runs on any environment such as Dev, UAT, Production.

We can significantly reduce the delay between writing the codes and running applications in the Production environment.

Using docker, We can segregate the applications from the infrastructure. By doing so we can quickly deliver the applications.

Docker has components such as Docker client, Docker server, Docker Hub, Docker Compose, etc.

Also read: How to Install and Configure Jenkins on Centos 7

What is Docker Containers?

A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.

Docker Containers

A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries, & settings.

=>Container images become containers at runtime and in the case of Docker =>containers — images become containers when they run on Docker Engine.

Docker containers that run on Docker Engine:

Standard: Docker created the industry standard for containers, so they could be portable anywhere

Lightweight: Containers share the machine’s OS system kernel and therefore do not require an OS per application, driving higher server efficiencies and reducing server and licensing costs

Secure: Applications are safer in containers and Docker provides the strongest default isolation capabilities in the industry

Features of Docker

Here is the list of some of the great features of Docker,

● Faster and easier configuration
● Swarm
● Application isolation
● Increase in productivity
● Better Software Delivery
● Routing Mesh
● Security Management
● Rapid scaling of Systems
● Software-defined networking

You may also like: Create SQL Server Database in AWS RDS

What is Docker Compose?

Docker-compose is a tool for defining and running multi-container docker applications.

We will use a YAML file to configure definitions for the applications and services. Once the compose file is ready, We can easily deploy and manage docker applications using a single file.

Docker-compose is basically a three-step process:

● Define the application’s environment in Dockerfile

● Define the services that will create an application in the docker-compose.yml file so that they can run together in isolated environments.

● Then run docker-compose up to start and run the applications Docker compose can perform the following actions:

● Start, Stop and Rebuild the services

● Check the status of the running applications

● Stream log out of the running services

● Running a one-off command on a service

Example of Docker composes file.

version: ‘3’ services:
image: nginx db:
image: mysql ports:
- “3306:3306”
- MYSQL_ROOT_PASSWORD=securepassword
- MYSQL_USER=someuser
- MYSQL_PASSWORD=securepassword1

What is Docker Engine?

Docker Engine is a Client-server application that has 3 major components.

● A docker daemon (the docker command), which is a long-running program, Also referred to as a service

● A REST API specifies the interface that programs can use to communicate with daemons and run commands against it.

● docker command, a command-line tool, called docker client.

Docker Engine

Installing Docker Packages on Centos

Docker engines can be installed in different ways.

a) By Setting up a Docker repository on the system and installing using it.

b) Download the RPM package and install packages manually.

Let us go ahead and install the stable version of Docker on Centos using the commands provided below.

Make sure you have sudo or root privileges to execute the following commands. First, we need to install the yum-config-manager utility,

sudo yum install yum-utils -y

Let's add the Docker repository to the system, Using the below command.

sudo yum-config-manager — add-repo

Let's go ahead and install the latest version of the Docker engine and containers packages,

sudo yum install docker-ce docker-ce-cli

After the packages are installed, We can start the Docker service.

The above installation will create a systemd unit file using which we can manage the Docker service.

cat /usr/lib/systemd/system/docker.service

Start and Enable the Docker service using the below commands.

systemctl start docker

systemctl enable docker

To check the status of the docker, Run the below command.

systemctl status docker

We can check the version of the Docker engine installed.

sudo docker — version

If you wish to install the specific version of the docker engine from the repository.First list the available versions in the repo and then we will install the specific version of docker.

yum list docker-ce — showduplicates | sort -r

To install the specific version, Users can select the version string from the second column.

For example : 17.12.1.ce-1.el7.centos

Let's install the above-mentioned version using the below command.

sudo yum install docker-ce-17.12.1.ce-1.el7.centos

If you are installing a custom version of docker and If the docker is already present on the system, The above commands with either Upgrade or Downgrade the docker version depending on the currently installed version of Docker.

Once installation is completed, Check the docker service and enable it to run on system boot.

Installing Docker Compose on CentOS

Docker-compose relies on the Docker engine, So make sure the docker engine is installed on the system, either local or remote.

Let's install the docker-compose on the Centos system.

Run the below command to download the current stable release of Docker compose.

sudo curl -L “ er-compose-$(uname -s)-$(uname -m)” -o


Apply the executable permission for the binary file which we have downloaded.

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

If the docker-compose is installed on a different location For example:

/usr/local/bin/ , You can copy the executable to /usr/bin directory.

You can check the version of docker-compose using the below command.

docker-compose — version



Zenesys Technosys

Zenesys is an 11-year-old IT Company based in the USA. Our key services: Mobile & Web Development, RPA, CMS, UI/UX & Cloud Services, etc. with the best solution