How To Install Docker on CentOS 8 / RHEL 8


Install Docker on CentOS 8
Install Docker on CentOS 8

Docker is a tool that allows you to easily build, test and deploy applications smoothly and quickly using containers. It has gained widespread popularity in recent times due to the portability to run applications anywhere irrespective of the host operating system.

Docker provides a more efficient and lightweight environment to deploy the application. Docker uses Kernel’s features such as cgroups and namespace to run a container on a single os instance.

In this post, you will learn how to install Docker on CentOS 8 / RHEL 8.


Install Docker On CentOS 8 / RHEL 8

Docker is now available in two editions,

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

Here, we will install Docker Comunity Edition (CE).


Uninstall Older Version

Uninstall older versions of Dockers, named docker or docker-engine along with associated dependencies.

yum -y remove docker-common docker container-selinux docker-selinux docker-engine

Do not worry about the contents inside /var/lib/docker/, all will be preserved.

Install Dependent Packages

Then, install the required packages.

yum -y install lvm2 device-mapper device-mapper-persistent-data device-mapper-event device-mapper-libs device-mapper-event-libs

Add Docker Repository

At the time of writing this article, Docker Inc is yet to release Docker packages for CentOS 8 / RHEL 8.. However, we can install Docker on CentOS 8 / RHEL 8 using the compatible packages (Docker rpm for CentOS 7 / RHEL 7).

Let’s add the CE repository for the Docker installation.

curl -o /etc/yum.repos.d/docker-ce.repo

Install Docker

Docker community edition requires >= 1.2.2-3 which is not available for CentOS 8 / RHEL 8. So, you have to skip the unavailable package and proceed to the installation which is not recommended. Since this is the only option we have at this moment to install Docker, you can go ahead and do it with your own RISK.
yum install docker-ce


Last metadata expiration check: 0:01:06 ago on Tue 12 Dec 2019 21:40:10 PM EST.
Error: Problem: package docker-ce-3:19.03.5-3.el7.x86_64 requires >= 1.2.2-3, but none of the providers can be installed - cannot install the best candidate for the job - package is excluded - package is excluded - package is excluded - package is excluded - package is excluded - package is excluded
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

Install the Docker CE by skipping the unavailable package.

yum -y install docker-ce --nobest


Last metadata expiration check: 0:04:12 ago on Tue 12 Dec 2019 21:41:41 PM EST.
Dependencies resolved. Problem: package docker-ce-3:19.03.5-3.el7.x86_64 requires >= 1.2.2-3, but none of the providers can be installed - cannot install the best candidate for the job - package is excluded - package is excluded - package is excluded - package is excluded - package is excluded - package is excluded
========================================================================================================= Package Arch Version Repository Size
Installing: docker-ce x86_64 3:18.09.1-3.el7 docker-ce-stable 19 M
Installing dependencies: container-selinux noarch 2:2.94-1.git1e99f1d.module_el8.0.0+58+91b614e7 AppStream 43 k checkpolicy x86_64 2.8-2.el8 BaseOS 338 k libcgroup x86_64 0.41-19.el8 BaseOS 70 k policycoreutils-python-utils noarch 2.8-16.1.el8 BaseOS 228 k python3-audit x86_64 3.0-0.10.20180831git0047a6c.el8 BaseOS 85 k python3-libsemanage x86_64 2.8-5.el8 BaseOS 127 k python3-policycoreutils noarch 2.8-16.1.el8 BaseOS 2.2 M python3-setools x86_64 4.2.0-2.el8 BaseOS 598 k tar x86_64 2:1.30-4.el8 BaseOS 838 k x86_64 1.2.0-3.el7 docker-ce-stable 22 M docker-ce-cli x86_64 1:19.03.5-3.el7 docker-ce-stable 39 M
Enabling module streams: container-tools rhel8
Skipping packages with broken dependencies: docker-ce x86_64 3:19.03.5-3.el7 docker-ce-stable 24 M Transaction Summary
Install 12 Packages
Skip 1 Package Total download size: 85 M
Installed size: 351 M
Downloading Packages:
(1/12): libcgroup-0.41-19.el8.x86_64.rpm 61 kB/s | 70 kB 00:01
(2/12): container-selinux-2.94-1.git1e99f1d.module_el8.0.0+58+91b614e7.n 35 kB/s | 43 kB 00:01
(3/12): policycoreutils-python-utils-2.8-16.1.el8.noarch.rpm 2.6 MB/s | 228 kB 00:00
(4/12): checkpolicy-2.8-2.el8.x86_64.rpm 265 kB/s | 338 kB 00:01
(5/12): python3-libsemanage-2.8-5.el8.x86_64.rpm 1.6 MB/s | 127 kB 00:00
(6/12): python3-audit-3.0-0.10.20180831git0047a6c.el8.x86_64.rpm 517 kB/s | 85 kB 00:00
(7/12): python3-policycoreutils-2.8-16.1.el8.noarch.rpm 6.9 MB/s | 2.2 MB 00:00
(8/12): tar-1.30-4.el8.x86_64.rpm 3.6 MB/s | 838 kB 00:00
(9/12): python3-setools-4.2.0-2.el8.x86_64.rpm 1.8 MB/s | 598 kB 00:00
(10/12): docker-ce-18.09.1-3.el7.x86_64.rpm 7.2 MB/s | 19 MB 00:02
(11/12): 6.9 MB/s | 22 MB 00:03
(12/12): docker-ce-cli-19.03.5-3.el7.x86_64.rpm 6.3 MB/s | 39 MB 00:06
Total 7.7 MB/s | 85 MB 00:10
warning: /var/cache/dnf/docker-ce-stable-091d8a9c23201250/packages/ Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Docker CE Stable - x86_64 1.2 kB/s | 1.6 kB 00:01
Importing GPG key 0x621E9F35: Userid : "Docker Release (CE rpm) <>" Fingerprint: 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35 From :
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction Preparing : 1/1 Installing : docker-ce-cli-1:19.03.5-3.el7.x86_64 1/12 Running scriptlet: docker-ce-cli-1:19.03.5-3.el7.x86_64 1/12 Installing : 2/12 Running scriptlet: 2/12 Installing : tar-2:1.30-4.el8.x86_64 3/12 Running scriptlet: tar-2:1.30-4.el8.x86_64 3/12 Installing : python3-setools-4.2.0-2.el8.x86_64 4/12 Installing : python3-libsemanage-2.8-5.el8.x86_64 5/12 Installing : python3-audit-3.0-0.10.20180831git0047a6c.el8.x86_64 6/12 Running scriptlet: libcgroup-0.41-19.el8.x86_64 7/12 Installing : libcgroup-0.41-19.el8.x86_64 7/12 Running scriptlet: libcgroup-0.41-19.el8.x86_64 7/12 Installing : checkpolicy-2.8-2.el8.x86_64 8/12 Installing : python3-policycoreutils-2.8-16.1.el8.noarch 9/12 Installing : policycoreutils-python-utils-2.8-16.1.el8.noarch 10/12 Installing : container-selinux-2:2.94-1.git1e99f1d.module_el8.0.0+58+91b614e7.noarch 11/12 Running scriptlet: container-selinux-2:2.94-1.git1e99f1d.module_el8.0.0+58+91b614e7.noarch 11/12 Running scriptlet: docker-ce-3:18.09.1-3.el7.x86_64 12/12 Installing : docker-ce-3:18.09.1-3.el7.x86_64 12/12 Running scriptlet: docker-ce-3:18.09.1-3.el7.x86_64 12/12 Verifying : container-selinux-2:2.94-1.git1e99f1d.module_el8.0.0+58+91b614e7.noarch 1/12 Verifying : checkpolicy-2.8-2.el8.x86_64 2/12 Verifying : libcgroup-0.41-19.el8.x86_64 3/12 Verifying : policycoreutils-python-utils-2.8-16.1.el8.noarch 4/12 Verifying : python3-audit-3.0-0.10.20180831git0047a6c.el8.x86_64 5/12 Verifying : python3-libsemanage-2.8-5.el8.x86_64 6/12 Verifying : python3-policycoreutils-2.8-16.1.el8.noarch 7/12 Verifying : python3-setools-4.2.0-2.el8.x86_64 8/12 Verifying : tar-2:1.30-4.el8.x86_64 9/12 Verifying : 10/12 Verifying : docker-ce-3:18.09.1-3.el7.x86_64 11/12 Verifying : docker-ce-cli-1:19.03.5-3.el7.x86_64 12/12 Installed: docker-ce-3:18.09.1-3.el7.x86_64 container-selinux-2:2.94-1.git1e99f1d.module_el8.0.0+58+91b614e7.noarch checkpolicy-2.8-2.el8.x86_64 libcgroup-0.41-19.el8.x86_64 policycoreutils-python-utils-2.8-16.1.el8.noarch python3-audit-3.0-0.10.20180831git0047a6c.el8.x86_64 python3-libsemanage-2.8-5.el8.x86_64 python3-policycoreutils-2.8-16.1.el8.noarch python3-setools-4.2.0-2.el8.x86_64 tar-2:1.30-4.el8.x86_64 docker-ce-cli-1:19.03.5-3.el7.x86_64 Skipped: docker-ce-3:19.03.5-3.el7.x86_64 Complete!

You can also install a particular version of Docker CE by appending version like docker-ce-[version]
E.g. yum install docker-ce-19.03.5-3.el7
You can list the available Docker versions with yum list docker-ce –showduplicates | sort -r

Now you have Docker installed onto your machine, start the Docker service in case if it is not started automatically after the installation

systemctl start docker systemctl enable docker

Check the Docker service.

systemctl status docker
Docker Service Status
Docker Service Status

Verify Docker Installation

Once you start the Docker service, you can run a simple “Hello World” container to verify the installation.

docker run -it centos echo Hello-World

When we run the docker run command, the Docker creates and starts the container with the base image of CentOS.


Since we are running centos container for the first time, the output will look like below.

Unable to find image 'centos:latest' locally
latest: Pulling from library/centos
729ec3a6ada3: Pull complete
Digest: sha256:f94c1d992c193b3dc09e297ffd54d8a4f1dc946c37cbeceb26d35ce1647f88d9
Status: Downloaded newer image for centos:latest
Hello World Container
Hello World Container

At first, the Docker looks for centos image locally, and if it is not found, it starts downloading the centos image from the Docker registry (one time). Otherwise, it uses the already downloaded centos image. Once the image has been downloaded (in our case), it will start the container and echo the command Hello-World in the console which you can see at the end of the output.

Allow Non-root access

By default, only users with root or sudo (root) privilege can run Docker containers. To allow non-root users to run Docker containers, you can follow the below steps.

Create a group called docker if it does not exist, run the following commands with root privileges.

groupadd docker

Add a user that is to be a part of the docker group. Replace raj with your username.

useradd raj

Add a user to the docker group.

usermod -aG docker raj

Now you can run a Docker with a non-root user.


Consider disabling the FirewallD service to allow all your services accessible outside the Docker host without connection issues.

When firewalld is ON and started or restarted, it will remove the DOCKER chain from iptables, it prevents Docker from working properly.

systemctl stop firewalld systemctl disable firewalld

If you still want to use a firewall, the firewalld is must be started before Docker service. In case if you start or restart firewalld after Docker, you will have to restart the Docker daemon.

Interested Topics

Docker Basic Topics

1: Top Important Docker Commands – Working with Docker Containers

2: Working with Docker Images – Building Docker Images

3: How to Build Docker Images with DockerFile

Docker Advanced Topics

1: How to Setup Docker Private Registry on CentOS 7

2: How to Install and Configure Docker Swarm on CentOS 7


That’s All. Please share your feedback in the comments section.