How to Install and Setup Docker CE on CentOS 8 / RHEL 8

Docker is an open source project which allows the creation and distribution of applications inside containers, which are standardized environments that can be easily replicated, independently from the host system. While in Red Hat Enterprise Linux 7 Docker was officially supported, on the new release of this open source operating system, it has been replaced by a series of other tools developed by Red Hat itself: buildah and podman.

About CentOS 8 DNF Command:

DNF stands for Dandified YUM is a software package manager for RPM-based Linux distributions. It is used to install, update and remove packages in the Fedora/RHEL/CentOS operating system. It is the default package manager of Fedora 22, CentOS8 and RHEL8. DNF is the next generation version of YUM and intended to be the replacement for YUM in RPM-based systems. DNF is powerful and has robust features than you’ll find in yum. DNF makes it easy to maintain groups of packages and capable of automatically resolving dependency issues.

yum install dnf

$ dnf --version
4.2.7
  Installed: dnf-0:4.2.7-7.el8_1.noarch at Wed 11 Mar 2020 09:23:01 AM GMT
  Built    : CentOS Buildsys <bugs@centos.org> at Thu 19 Dec 2019 03:44:23 PM GMT

  Installed: rpm-0:4.14.2-25.el8.x86_64 at Wed 11 Mar 2020 01:25:56 PM GMT
  Built    : CentOS Buildsys <bugs@centos.org> at Fri 08 Nov 2019 10:56:14 PM GMT

Installation Steps of Docker CE on CentOS 8 / RHEL 8 Server

By the use of an external repository, however, it’s still possible to install Docker CE (Community Edition). In this tutorial we will see how to install repository to obtain the software because the community version of Docker has no official support for Red Hat Enterprise Linux.

Docker Available Versions

    Docker CE (Community Edition)
    Enterprise Edition (EE)

In this guide we will learn how to install Docker CE (Community Edition) on CentOS 8 or RHEL 8 Server.

System Requirements for Docker CE

    Minimal CentOS 8 / RHEL 8
    Sudo or root privileges
    Internet Connection

Enable Docker CE Repository

$ sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
Adding repo from: https://download.docker.com/linux/centos/docker-ce.repo

Install Docker CE using dnf command

$ sudo dnf list docker-ce
CentOS-8 - AppStream                                                                           4.0 kB/s | 4.3 kB     00:01
CentOS-8 - Base                                                                                3.5 kB/s | 3.8 kB     00:01
CentOS-8 - Extras                                                                              2.7 kB/s | 1.5 kB     00:00
Docker CE Stable - 86_64                                                                       24 kB/s  | 22 kB      00:00
Available Packages
docker-ce.x86_64                                                                               3:19.03.7-3.el7       docker-ce-stable

$ sudo dnf install docker-ce --nobest -y

Docker CE Stable - x86_64                                                                      6.6 kB/s | 1.6 kB     00:00
Importing GPG key 0x621E9F35:
 Userid     : "Docker Release (CE rpm) <docker@docker.com>"
 Fingerprint: 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
 From       : https://download.docker.com/linux/centos/gpg
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.7-3.el7.x86_64                                     1/4
  Running scriptlet: docker-ce-cli-1:19.03.7-3.el7.x86_64                                     1/4
  Installing       : containerd.io-1.2.0-3.el7.x86_64                                         2/4
  Running scriptlet: containerd.io-1.2.0-3.el7.x86_64                                         2/4
  Running scriptlet: libcgroup-0.41-19.el8.x86_64                                             3/4
  Installing       : libcgroup-0.41-19.el8.x86_64                                             3/4
  Running scriptlet: libcgroup-0.41-19.el8.x86_64                                             3/4
  Running scriptlet: docker-ce-3:18.09.1-3.el7.x86_64                                         4/4
  Installing       : docker-ce-3:18.09.1-3.el7.x86_64                                         4/4
  Running scriptlet: docker-ce-3:18.09.1-3.el7.x86_64                                         4/4
  Verifying        : libcgroup-0.41-19.el8.x86_64                                             1/4
  Verifying        : containerd.io-1.2.0-3.el7.x86_64                                         2/4
  Verifying        : docker-ce-3:18.09.1-3.el7.x86_64                                         3/4
  Verifying        : docker-ce-cli-1:19.03.7-3.el7.x86_64                                     4/4

Installed:
  docker-ce-3:18.09.1-3.el7.x86_64                           libcgroup-0.41-19.el8.x86_64                           containerd.io-1.2.0-3.el7.x86_64                           docker-ce-cli-1:19.03.7-3.el7.x86_64

Skipped:
  docker-ce-3:19.03.7-3.el7.x86_64

Complete!

Start and Enable the Docker Daemon

Once docker-ce is installed, we must start and enable the docker daemon, so that it will be also launched automatically at boot. The command we need to run is the following:

$ sudo systemctl enable --now docker

At this point, we can confirm that the daemon is active by running:

$ sudo systemctl start docker

$ systemctl is-active docker
active

Similarly, we can check that it is enabled at boot, by running:

$ systemctl is-enabled docker
enabled

Run the following command to verify installed docker version

$ docker --version
Docker version 19.03.7, build 7141c199a2

Verify and Test Docker CE Engine

$ sudo docker run centos
Unable to find image 'centos:latest' locally
latest: Pulling from library/centos
8a29a15cefae: Pull complete
Digest: sha256:fe8d824220415eed5477b63addf40fb06c3b049404242b31982106ac204f6700
Status: Downloaded newer image for centos:latest

$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
53e807058dd5        centos              "/bin/bash"         41 seconds ago      Exited (0) 39 seconds ago                       hopeful_dirac

$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              latest              470671670cac        7 weeks ago         237MB

$ sudo docker run -it centos
[root@cd4f766147f3 /]#

Install Docker Compose

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   617  100   617    0     0    638      0 --:--:-- --:--:-- --:--:--   638
100 16.2M  100 16.2M    0     0   988k      0  0:00:16  0:00:16 --:--:-- 1199k

Set the executable permission to docker-compose binary.

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

Check the docker compose version with following command.

$ docker-compose --version
docker-compose version 1.25.0, build 0a186604

Conclusion:

Basically, that’s all you need to know about Docker setup on CentOS 8 and RHEL 8. There are more tutorials that will go into deeper explanation of using Docker thoroughly, but this is a simple article to just get familiar with the concept of Docker.

Avatar photo

Asif Khan

Responsible and proactive professional with more than 13 years of experience in IT systems, open source software applications, DevOps, Linux systems, and cloud operations. My main goals are to automate things, keep them safe, and make sure they are strong. I am very good at planning and building the infrastructure for services that people really want. I was drawn to the fast-paced world of cloud computing because it has resources that can be scaled up or down as needed. One of my best skills is being able to use a lot of different DevOps tools to set up, release management, and microservices ecosystems, as well as for provisioning, orchestration, and configuration management.