What is Docker?
Docker is an open-source platform based on the containerization concept. Docker provides the ability to package and run any type of application in an isolated environment, which is known as a container. In simple words, we can say that a docker is a system-friendly software or platform for developing, shipping, and running any type of application. Learn How to install docker and docker-compose in CentOS 8.
Docker provides a platform where applications run in a container that can be easily moved to any system. Docker hub offers a variety of pre-developed images to use. It has repositories where users can easily fetch the images and deploy the application that can later be used by the public.
What is Docker Compose?
Docker-compose is a useful tool that is developed to define and run multi-container applications. We will use a YAML file to define and configure the containers for the application. After creating the YAML file, we can easily deploy and manage the docker containers for the application by using a single file.
Docker-compose process can be defined in three simple steps:
- Define the environment for the application in the Dockerfile.
- In docker-compose.yml file, define the services which you want to use in your application such as MySQL, PHP etc.
- Run the command docker-compose up -d to start and run the application.
Example of docker-compose.yml file.
version: '3' services: web: image: httpd ports: - 80:80 db: image: mariadb restart: always ports: - "3306:3306" environment: MYSQL_ROOT_PASSWORD: 'root_password' MYSQL_USER: 'linuxpanda' MYSQL_PASSWORD: 'password' MYSQL_DATABASE: 'linux_db'
the docker-compose.yml file will look like this. The alignment of every line must be perfect, otherwise when we run the docker-compose up -d command, then the docker-compose.yml file will show an error.
Installing Docker packages.
First, we need to install the yum-config-manager utility.
sudo yum install yum-utils -y
Now add the Docker repository so that we can install the docker package directly from the repository, run the below command to install and enable the repository.
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Now run the following command to install the latest docker version.
sudo yum install docker-ce docker-ce-cli containerd.io -y
After installation, we need to start the docker service. To start the docker, run the following command.
systemctl start docker
To check the version of docker.
sudo docker --version
If you want to install any specific docker version from the docker repository. First, you need to check the available version of docker in the docker repository.
yum list docker-ce --showduplicates | sort -r
From the second column, select the docker version which you want to install.
For example, you want to install docker version 18.09.0-3.el7.
To install the above-mentioned docker version, run the following command.
sudo yum install docker-ce-18.09.0-3.el7 -y
If your server or system already has docker installed in it, then the above command will either Downgrade or Upgrade the docker version. It depends on the version of docker which is currently installed on your system.
Manage the Docker service
To start the Docker service.
sudo systemctl start docker
To Status the Docker service.
sudo systemctl status docker
For Enable the Docker service.
sudo systemctl enable docker
To Stop the Docker service.
sudo systemctl stop docker
To Disable the Docker service.
sudo systemctl disable docker
For Restart the Docker service.
sudo systemctl restart docker
Installing Docker Compose
Docker-compose fully depends on the docker without docker, it’s not possible to run the docker-compose. So make sure that the docker is perfectly installed on your system or server.
To install the Docker Compose on your CentOS server, run the below command to download and install the current stable release of Docker Compose.
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Grant the executable permission for the binary file which we have downloaded from the above command.
sudo chmod +x /usr/local/bin/docker-compose
In most cases, docker-compose fails after installation because docker-compose may be installed on a different path. You need to create a symbolic link to /usr/bin .
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
To check the Docker Compose, run the following command.
In this tutorial, we have learned how to install and configure the Docker and Docker-compose on CentOS 8. You can follow the same tutorial for the CentOS 7 operating system.
You can also learn how to install and configure the Docker on Ubuntu 20.04 Server, just follow our another blog for Docker installation on Ubuntu 20.04
If you guys have any queries related to this tutorial, then let me know in the comment section.