How to install Docker on CentOS 8

CentOS 8 comes with its own tools, builddah and podman, which are compatible with existing docker images and work without relying on daemons, allowing containers to be created as normal users without special permissions.

These tools still have some limitations, so in this tutorial we will learn how to use the official Docker repository to install and run the original Docker CE on Centos 8.

What is Docker?

Docker is an open source project that allows applications to be created and distributed inside containers, which are standardized environments that can be easily replicated independently of the host system.

Add Docker repository

First, we have to add an external repository to get Docker CE. We will use the official Docker CE CentOS repository.

Among other features, the DNF config-manager utility enables us to easily enable or disable repositories in CentOS. By default, only appstream and baseos repositories are enabled on CentOS 8. The next step is to also add and enable the docker-ce repo. To accomplish this task, all we have to do is run the following command:

$ 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

We can verify that the repository is enabled by typing the following dnf command:

$ sudo dnf repolist -v

....

Repo-id      : docker-ce-stable
Repo-name    : Docker CE Stable - x86_64
Repo-revision: 1567619328
Repo-updated : Wed 04 Sep 2019 05:48:48 PM UTC
Repo-pkgs    : 51
Repo-size    : 1.1 G
Repo-baseurl : https://download.docker.com/linux/centos/7/x86_64/stable
Repo-expire  : 172,800 second(s) (last: Mon 30 Sep 2019 09:28:09 PM UTC)
Repo-filename: /etc/yum.repos.d/docker-ce.repo

Install docker-ce package

The repository contains multiple versions of the docker-ce package. To display all versions, we can run:

$ dnf list docker-ce --showduplicates | sort -r
Extra Packages for Enterprise Linux 8 - x86_64  501 kB/s | 2.3 MB     00:04    
docker-ce.x86_64            3:19.03.4-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.3-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.2-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.1-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.0-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.9-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.8-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.7-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.6-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.5-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.4-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.3-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.2-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.1-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.0-3.el7                     docker-ce-stable
docker-ce.x86_64            18.06.3.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.2.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.1.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.0.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            18.03.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.3.ce-1.el7                    docker-ce-stable
docker-ce.x86_64            17.03.2.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.0.ce-1.el7.centos             docker-ce-stable

Currently, the installation of containerd.io> 1.2.0-3.el7 is blocked, which is a dependency of docker-ce. Therefore, we must address this issue. However, there is another problem. As long as firewalld is enabled and the system firewall manager is enabled, DNS resolution within the docker container will not work properly. Currently, this is the only way to install docker-ce. We will update this article once the appropriate centos 8 packages are available.

Now we will install docker using the following command:

$ sudo dnf -y  install docker-ce --nobest
Last metadata expiration check: 0:35:54 ago on Sun 20 Oct 2019 05:17:37 PM UTC.
Dependencies resolved.

 Problem: package docker-ce-3:19.03.4-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
================================================================================
 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
 libcgroup         x86_64 0.41-19.el8                    BaseOS            70 k
 containerd.io     x86_64 1.2.0-3.el7                    docker-ce-stable  22 M
 docker-ce-cli     x86_64 1:19.03.4-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.4-3.el7                docker-ce-stable  24 M

Transaction Summary
================================================================================
Install  5 Packages
Skip     1 Package

Total download size: 80 M
Installed size: 338 M
Downloading Packages:
(1/5): container-selinux-2.94-1.git1e99f1d.modu 314 kB/s |  43 kB     00:00    
(2/5): libcgroup-0.41-19.el8.x86_64.rpm         470 kB/s |  70 kB     00:00    
(3/5): containerd.io-1.2.0-3.el7.x86_64.rpm     3.1 MB/s |  22 MB     00:07    
(4/5): docker-ce-18.09.1-3.el7.x86_64.rpm       2.6 MB/s |  19 MB     00:07    
(5/5): docker-ce-cli-19.03.4-3.el7.x86_64.rpm   2.6 MB/s |  39 MB     00:15    
--------------------------------------------------------------------------------
Total                                           4.5 MB/s |  80 MB     00:17     
warning: /var/cache/dnf/docker-ce-stable-091d8a9c23201250/packages/containerd.io-1.2.0-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Docker CE Stable - x86_64                       1.4 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       : 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.4-3.el7.x86_64                   1/5 
  Running scriptlet: docker-ce-cli-1:19.03.4-3.el7.x86_64                   1/5 
  Installing       : containerd.io-1.2.0-3.el7.x86_64                       2/5 
  Running scriptlet: containerd.io-1.2.0-3.el7.x86_64                       2/5 
  Running scriptlet: libcgroup-0.41-19.el8.x86_64                           3/5 
  Installing       : libcgroup-0.41-19.el8.x86_64                           3/5 
  Running scriptlet: libcgroup-0.41-19.el8.x86_64                           3/5 
  Installing       : container-selinux-2:2.94-1.git1e99f1d.module_el8.0.0   4/5 
  Running scriptlet: container-selinux-2:2.94-1.git1e99f1d.module_el8.0.0   4/5 
  Running scriptlet: docker-ce-3:18.09.1-3.el7.x86_64                       5/5 
  Installing       : docker-ce-3:18.09.1-3.el7.x86_64                       5/5 
  Running scriptlet: docker-ce-3:18.09.1-3.el7.x86_64                       5/5 
  Verifying        : container-selinux-2:2.94-1.git1e99f1d.module_el8.0.0   1/5 
  Verifying        : libcgroup-0.41-19.el8.x86_64                           2/5 
  Verifying        : containerd.io-1.2.0-3.el7.x86_64                       3/5 
  Verifying        : docker-ce-3:18.09.1-3.el7.x86_64                       4/5 
  Verifying        : docker-ce-cli-1:19.03.4-3.el7.x86_64                   5/5 

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       
  libcgroup-0.41-19.el8.x86_64                                                  
  containerd.io-1.2.0-3.el7.x86_64                                              
  docker-ce-cli-1:19.03.4-3.el7.x86_64                                          

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

Complete!

Now we must enable the docker service:

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

We can check if the service is running normally:

$ systemctl status  docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor pres>
   Active: active (running) since Sun 2019-10-20 18:00:45 UTC; 2min 12s ago
     Docs: https://docs.docker.com
 Main PID: 2856 (dockerd)
    Tasks: 21
   Memory: 53.2M
   CGroup: /system.slice/docker.service
           ├─2856 /usr/bin/dockerd -H fd://
           └─2873 containerd --config /var/run/docker/containerd/containerd.tom>

It can be seen that everything is normal.

Add user to Docker group

The docker group has been created, but no users have been added to the group. Add your users to this group to run docker commands without sudo.

$ sudo usermod -aG docker $USER
$ id $USER
uid=1000(vagrant) gid=1000(vagrant) groups=1000(vagrant),988(docker)

Log out and log in again to use Docker without sudo. We can check the docker version using:

$ newgrp docker

$ docker version
Client: Docker Engine - Community
 Version:           19.03.4
 API version:       1.39 (downgraded from 1.40)
 Go version:        go1.12.10
 Git commit:        9013bf583a
 Built:             Fri Oct 18 15:52:22 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.1
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.6
  Git commit:       4c52b90
  Built:            Wed Jan  9 19:06:30 2019
  OS/Arch:          linux/amd64
  Experimental:     false

Test docker installation by pulling test image

Now we can pull the alpine docker container image to test the installed docker:

$ docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
9d48c3bd43c5: Pull complete 
Digest: sha256:72c42ed48c3a2db31b7dafe17d275b634664a708d901ec9fd57b1529280f01fb
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest

List downloaded container images:

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
alpine              latest              961769676411        2 months ago        5.58MB

Verify that Docker CE works by running the alpine container from the downloaded image.

$ docker run -it --rm alpine /bin/sh
/ # apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.10/main: temporary error (try again later)
WARNING: Ignoring APKINDEX.00740ba1.tar.gz: No such file or directory
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.10/community: temporary error (try again later)
WARNING: Ignoring APKINDEX.d8b2a6f4.tar.gz: No such file or directory
2 errors; 14 distinct packages available
/ # exit

We see here that we encountered an error when trying to update with “apk update”.

As mentioned earlier, in order for DNS resolution to work in Docker containers, we must disable firewalld (may also need to restart the system):

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

After restarting, we will try the apk update again:

$ docker run -it --rm alpine /bin/sh
/ # apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz
v3.10.2-189-g393dc02e8c [http://dl-cdn.alpinelinux.org/alpine/v3.10/main]
v3.10.2-189-g393dc02e8c [http://dl-cdn.alpinelinux.org/alpine/v3.10/community]
OK: 10337 distinct packages available
/ # exit

And now it works. This is not a good solution, but for now, this is the only way. Now you can ssh into docker and start using it.

in conclusion

Currently, there is no official Centos 8 Docker software package. Currently, we must use this alternative to use official Docker. In this tutorial, we learned how to install and use Docker and Docker images, which is the only workaround currently known.

Also read:

  • How to install Docker on Ubuntu 18.04 (2019 update)
Sidebar