How To'sLinux

How to Install Docker CE on CentOS 8, 7 / RHEL 8

We can deploy apps inside containers using the daemon-based container engine Docker. Docker has been replaced by podman and buildah in the default package repositories of RHEL 8 and CentOS 8 and is no longer available.

In this tutorial, we’re going to install Docker CE on RHEL 8 through the official Docker repository for CentOS 8. You can build, and operate apps in containers along with their dependencies. Microservices environments often use containers.

Docker version

  • Docker CE (Community Edition)
  • Enterprise Edition (EE)

Let’s get started!

How to install Docker on CentOS 8

1. Update

Before, getting started we should update our CentOS 8 using the following command.

dnf update -y

And reboot your system using the reboot command to finish the update.

2. Add Docker CE Repository

After you finished the update. Now, we can include the repository for Docker CE on CentOS 8 or RHEL 8. Use the following command to enable the Docker CE repository.

## CentOS 8 ##
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

## CentOS 7 ##
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

## RHEL 8 ##
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo

You can verify the repository that has been enabled by entering the following command:

dnf repolist -v

The above command will display the enabled repositories that your system has already installed.

install docker centos

3. Installing Docker CE

After enabling the docker-ce-stable repository on our system, to display the list of all available packages for docker you can execute the following command:

dnf list docker-ce --showduplicates | sort -r

install docker centos

Now, it’s your choice to install the specific version, that you require and compatible with the dependencies of your project.

Install Docker CE using dnf command

Let’s install the latest version of Docker CE using the dnf command.

dnf install docker-ce --nobest -y

Install Docker CE using yum command

Let’s install the latest version of Docker CE using the yum command.

yum install docker

Install a Specific Version of Docker on CentOS

To install the specific version of Docker on CentOS which we have already listed above, we’re gonna install the specific version.

sudo yum install docker-ce-<VERSION HERE>

You can replace the version of Docker with <VERSION HERE> to install that required version.

4. Manage Docker Service

After the installation of Docker, services such as start and enable can be managed using the systemctl. Now we’re going to start and enable docker for a startup.

systemctl start docker
systemctl enable docker

To check the docker service running you can use the following command.

systemctl status docker

After successful installation of docker, you can check the docker version which is installed using the following command.

docker --version

If you faced any difficulty or errors after installing docker such as, failed to start docker service unit docker service not found, docker daemon not running then you might wanna read this article.

Don’t Miss: How To Fix Error Starting Docker Service Unit Not Found?

5. Test And Verify Docker CE Engine

Now that you have installed docker-ce the engine you can verify whether it’s correctly installed or not so let’s spin up the “hello-world” and “alpine” container using the following command.

First, pull both the images from docker repositories.

docker pull hello-world

Another image you can pull is alpine to test out your docker is working correctly and ready to deploy real-world applications.

docker pull alpine

To find out what images you have downloaded you can use the following command to list.

docker images

As you can see you have two images hello-world and alpine you can get a bash shell on alpine by running the following command.

docker run -it --rm alpine /bin/bash

To run the hello-world application you can run the same following command.

docker run -it --rm hello-world

6. Installing Docker Compose

The purpose of docker-compose is to link multiple containers or it is helpful to deploy multiple containers which are dependent on each other. For example, LAMP where PHP, Apache, and MariaDB are running under dedicated containers.

dnf install curl -y
curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Global Installation docker-compose

Since it is available in the python package we can install it using pip.

dnf install python3-pip
pip3 install docker-compose --user

To find out what version of docker-compose is installed you can type the following command:

docker-compose --version

Conclusion

If you followed this guide you will have a successful installation of docker. If you faced any difficulties or issues please mention them in the comments and this article will be updated accordingly.

Noor Qureshi

Experienced Founder with a demonstrated history of working in the computer software industry. Skilled in Network Security and Information Security.

Leave a Reply

Your email address will not be published.

Back to top button