Installing Docker on RedHat/Centos 8

Docker is free and open-source software. It automates the deployment of any application as a lightweight, portable, self-sufficient container that will run virtually anywhere. Typically you develop software on your laptop/desktop. You can build a container with your app, and it can test run on your computer. It will scale in cloud, VM, VPS, bare-metal and more. There are two versions of docker. The first one bundled with RHEL/CentOS 7 distro and can be installed with the yum. The second version distributed by the Docker project called docker-ce (community free version) and can be installed by the official Docker project repo. The third version distributed by the Docker project called docker-ee (Enterprise paid version) and can be installed by the official Docker project repo.

Installing Docker CE in Red Hat 8

First thing we need to do is to install some prerequisites and then we can get onto install Docker CE (Community Edition). We will use dnf config manager to add the repo for docker in our environment. The default repos for RH8 are appstream and baseos. So we need to add additional repos for applications we want to install. Run the following command:

# sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo 
Updating Subscription Management repositories. Adding repo from: https://download.docker.com/linux/centos/docker-ce.repo

We can check to see if its installed by entering the command:

# sudo dnf repolist -v
....
Repo-id      : docker-ce-stable
Repo-name    : Docker CE Stable - x86_64
Repo-revision: 1581560354
Repo-updated : Wed 12 Feb 2020 09:19:14 PM EST
Repo-pkgs    : 59
Repo-size    : 1.3 G
Repo-baseurl : https://download.docker.com/linux/centos/7/x86_64/stable
Repo-expire  : 172,800 second(s) (last: Wed 31 Dec 1969 07:00:00 PM EST)
Repo-filename: /etc/yum.repos.d/docker-ce.repo
...

Now let’s get to why we’re here, installing Docker. Now that we have the repo we can install the version of what we like. Let’s look to see what’s available:

# dnf list docker-ce --showduplicates
Updating Subscription Management repositories.
Last metadata expiration check: 0:04:00 ago on Mon 24 Feb 2020 04:26:55 PM EST.
Available Packages
docker-ce.x86_64     17.03.0.ce-1.el7.centos   docker-ce-stable
docker-ce.x86_64     17.03.1.ce-1.el7.centos   docker-ce-stable
docker-ce.x86_64     17.03.2.ce-1.el7.centos   docker-ce-stable
docker-ce.x86_64     17.03.3.ce-1.el7                docker-ce-stable
''''
docker-ce.x86_64     3:19.03.3-3.el7                 docker-ce-stable
docker-ce.x86_64     3:19.03.4-3.el7                 docker-ce-stable
docker-ce.x86_64     3:19.03.5-3.el7                 docker-ce-stable
docker-ce.x86_64   3:19.03.6-3.el7                docker-ce-stable

We will use the latest and greatest version.

# dnf install docker-ce
Updating Subscription Management repositories.
Last metadata expiration check: 0:03:13 ago on Mon 24 Feb 2020 04:43:34 PM EST.
Error:
 Problem: package docker-ce-3:19.03.6-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
  - cannot install the best candidate for the job
  - package containerd.io-1.2.10-3.2.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.3.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.el7.x86_64 is excluded
  - package containerd.io-1.2.4-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.5-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.6-3.3.el7.x86_64 is excluded
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

OK looks like we have a problem. So apparently Red Hat blocks this package which is needed by Docker. There are a few workarounds and another issue with firewall not allowing DNS resolution within Docker I saw when I was looking for this install problem but will get to that later. Let get on with the install by installing the container packager then Docker. 

# dnf install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm -y
Updating Subscription Management repositories.
Last metadata expiration check: 0:14:55 ago on Mon 24 Feb 2020 04:43:34 PM EST.
containerd.io-1.2.6-3.3.el7.x86_64.rpm                                      23 MB/s |  26 MB     00:01
Dependencies resolved.
===========================================================================================================
 Package                    Architecture        Version                    Repository                 Size
===========================================================================================================
Upgrading:
 containerd.io              x86_64              1.2.6-3.3.el7              @commandline               26 M
     replacing  runc.x86_64 1.0.0-64.rc9.module+el8.1.1+5259+bcdd613a
Transaction Summary
===========================================================================================================
Upgrade  1 Package
Total size: 26 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                   1/1
  Running scriptlet: containerd.io-1.2.6-3.3.el7.x86_64                                                1/1
  Upgrading        : containerd.io-1.2.6-3.3.el7.x86_64                                                1/3
  Running scriptlet: containerd.io-1.2.6-3.3.el7.x86_64                                                1/3
  Running scriptlet: containerd.io-1.2.0-3.el7.x86_64                                                  2/3
  Cleanup          : containerd.io-1.2.0-3.el7.x86_64                                                  2/3
  Running scriptlet: containerd.io-1.2.0-3.el7.x86_64                                                  2/3
  Obsoleting       : runc-1.0.0-64.rc9.module+el8.1.1+5259+bcdd613a.x86_64                             3/3
  Running scriptlet: runc-1.0.0-64.rc9.module+el8.1.1+5259+bcdd613a.x86_64                             3/3
  Verifying        : containerd.io-1.2.6-3.3.el7.x86_64                                                1/3
  Verifying        : containerd.io-1.2.0-3.el7.x86_64                                                  2/3
  Verifying        : runc-1.0.0-64.rc9.module+el8.1.1+5259+bcdd613a.x86_64                             3/3
Installed products updated.
Upgraded:
  containerd.io-1.2.6-3.3.el7.x86_64
Complete!

Now let’s get Docker installed.

# dnf install docker-ce -y
Updating Subscription Management repositories.
Last metadata expiration check: 0:19:42 ago on Mon 24 Feb 2020 04:43:34 PM EST.
Dependencies resolved.
===========================================================================================================
 Package               Architecture   Version                  Repository                             Size
===========================================================================================================
Installing:
 docker-ce             x86_64         3:19.03.6-3.el7          docker-ce-stable                       24 M
Installing dependencies:
 docker-ce-cli         x86_64         1:19.03.6-3.el7          docker-ce-stable                       40 M
 libcgroup             x86_64         0.41-19.el8              rhel-8-for-x86_64-baseos-rpms          70 k
Transaction Summary
===========================================================================================================
Install  3 Packages
Total download size: 64 M
Installed size: 273 M
Downloading Packages:
(1/3): libcgroup-0.41-19.el8.x86_64.rpm                                    177 kB/s |  70 kB     00:00
(2/3): docker-ce-cli-19.03.6-3.el7.x86_64.rpm                               19 MB/s |  40 MB     00:02
(3/3): docker-ce-19.03.6-3.el7.x86_64.rpm                                   11 MB/s |  24 MB     00:02
-----------------------------------------------------------------------------------------------------------
Total                                                                       28 MB/s |  64 MB     00:02
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                   1/1
  Running scriptlet: libcgroup-0.41-19.el8.x86_64                                                      1/3
  Installing       : libcgroup-0.41-19.el8.x86_64                                                      1/3
  Running scriptlet: libcgroup-0.41-19.el8.x86_64                                                      1/3
  Installing       : docker-ce-cli-1:19.03.6-3.el7.x86_64                                              2/3
  Running scriptlet: docker-ce-cli-1:19.03.6-3.el7.x86_64                                              2/3
  Installing       : docker-ce-3:19.03.6-3.el7.x86_64                                                  3/3
  Running scriptlet: docker-ce-3:19.03.6-3.el7.x86_64                                                  3/3
  Verifying        : docker-ce-3:19.03.6-3.el7.x86_64                                                  1/3
  Verifying        : docker-ce-cli-1:19.03.6-3.el7.x86_64                                              2/3
  Verifying        : libcgroup-0.41-19.el8.x86_64                                                      3/3
Installed products updated.
Installed:
  docker-ce-3:19.03.6-3.el7.x86_64   docker-ce-cli-1:19.03.6-3.el7.x86_64   libcgroup-0.41-19.el8.x86_64
Complete!

Earlier I commented that there is a DNS restriction within Docker for Red Hat. In order to get around this we can disable the firewall or allow a firewall to pass a DNS request. I chose the latter but will provide both:

Option 1: Disable Firewall

# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus org.fedoraproject.FirewallD1.service.

Option 2: DNS Pass in Firewall (Preferred Option)

# firewall-cmd --permanent --zone=trusted --change-interface=docker0
success
# firewall-cmd --reload
success
# docker exec -it <CONTAINER_ID> bash
#  nslookup oracle.com 
nslookup: can't resolve '(null)'
Name:      oracle.com
Address 1: 137.254.120.50 vp-ocoma-cms-adc.oracle.com

The “nslookup: can’t resolve ‘(null)'” is no big deal and can be ignored.

Starting and Enabling Docker

We have it installed but we still need to enable it and start it.

# systemctl enable --now docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.

We can check for the status of Docker

# systemctl status  docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2020-02-24 17:09:19 EST; 53s ago
     Docs: https://docs.docker.com
 Main PID: 18126 (dockerd)
    Tasks: 13
   Memory: 46.4M
   CGroup: /system.slice/docker.service
           └─18126 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Feb 24 17:09:18 rhminisrv.localdomain dockerd[18126]: time="2020-02-24T17:09:18.915449496-05:00" level=inf>
Feb 24 17:09:18 rhminisrv.localdomain dockerd[18126]: time="2020-02-24T17:09:18.940770842-05:00" level=war>
Feb 24 17:09:18 rhminisrv.localdomain dockerd[18126]: time="2020-02-24T17:09:18.940803066-05:00" level=war>
Feb 24 17:09:18 rhminisrv.localdomain dockerd[18126]: time="2020-02-24T17:09:18.941016639-05:00" level=inf>
Feb 24 17:09:19 rhminisrv.localdomain dockerd[18126]: time="2020-02-24T17:09:19.238176586-05:00" level=inf>
Feb 24 17:09:19 rhminisrv.localdomain dockerd[18126]: time="2020-02-24T17:09:19.507760812-05:00" level=inf>
Feb 24 17:09:19 rhminisrv.localdomain dockerd[18126]: time="2020-02-24T17:09:19.560569954-05:00" level=inf>
Feb 24 17:09:19 rhminisrv.localdomain dockerd[18126]: time="2020-02-24T17:09:19.560670859-05:00" level=inf>
Feb 24 17:09:19 rhminisrv.localdomain dockerd[18126]: time="2020-02-24T17:09:19.593184366-05:00" level=inf>
Feb 24 17:09:19 rhminisrv.localdomain systemd[1]: Started Docker Application Container Engine.

That’s it for the Installation.