How to Install Docker & Docker-compose on Centos 7 | Fit-DevOps

Rahul K
FAUN — Developer Community 🐾
4 min readAug 12, 2020

--

This blog was originally published at https://fitdevops.in

All the Latest updates and Contents will be published there.

Don’t forget to check as I will post content everyday…

In the previous blog posts, we have learned how we can set up Redash dashboards with the help of docker and docker-compose.

So let us understand the basics of Docker and the installation procedure of Docker and Docker Compose.

What is Docker?

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

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

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

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 the 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 docker-compose.yml file so that they can run together in an isolated environment.
  • 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 compose file.

version: '3'
services:
web:
image: nginx
db:
image: mysql
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_USER=user
- MYSQL_PASSWORD=password
- MYSQL_DATABASE=testdb

What is Docker Engine?

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

  • A docker daemon (the dockerd 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 a docker client.

Installing Docker packages.

Docker engine can be installed in different ways.

a)Setup Docker repository on the system and install using it.

b)Download the RPM package and installing packages manually.

Make sure you have sudo or root privileges to execute the following commands.

First, we need to install 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 https://download.docker.com/linux/centos/docker-ce.repo

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

sudo yum install docker-ce docker-ce-cli containerd.io

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 dockersystemctl 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

Docker-compose relies on the docker engine, so make sure the docker engine is installed on the system, either on 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 "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

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

Conclusion

We have understood the basics of docker and we have learned how to install docker-engine and docker-compose on the Centos operating system.

Hope you find it helpful. Please do check out my other publications.

Originally published at https://fitdevops.in.

👋 Join FAUN today and receive similar stories each week in your inbox! Get your weekly dose of the must-read tech stories, news, and tutorials.

Follow us on Twitter 🐦 and Facebook 👥 and Instagram 📷 and join our Facebook and Linkedin Groups 💬

If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇

--

--

Pro-Active Devops Engineer with 5+ years of experience in Linux , Amazon Web Services, Azure , GCP , Devops tools. Blogs here : https://fitdevops.in