Installing Docker on CentOS 8

Installing Docker & Docker Compose on CentOS 7/RHEL 7 is quite straight forward, but this process is quite tricky in CentOS8/RHEL8. This is because of the fact that Docker is not officially supported on CentOS8/RHEL 8 as it has been replaced with Red Hat tools – buildah and podman. In this post we will go through the process of installing Docker Community Edition in CentOS 8 with minimal installation.

$ cat /etc/*-release CentOS Linux release 8.0.1905 (Core) NAME="CentOS Linux" VERSION="8 (Core)" ... CentOS Linux release 8.0.1905 (Core) CentOS Linux release 8.0.1905 (Core)

Update your system

$ dnf update -y

Install required packages

If this is the first time you install Docker on the machine, you will need to install the packages needed by Docker to run and set up the Docker repository.

$ sudo yum install -y yum-utils \   device-mapper-persistent-data \   lvm2

Output

CentOS-8 - AppStream                                                                                                                 1.6 kB/s | 4.3 kB     00:02 CentOS-8 - Base                                                                                                                      1.1 kB/s | 3.9 kB     00:03 CentOS-8 - Extras                                                                                                                    907  B/s | 1.5 kB     00:01 Package device-mapper-persistent-data-0.7.6-1.el8.x86_64 is already installed. Package lvm2-8:2.03.02-6.el8.x86_64 is already installed. Dependencies resolved. =====================================================================================================================================================================  Package                                 Arch                                 Version                                     Repository                            Size ===================================================================================================================================================================== Installing:  dnf-utils                               noarch                               4.0.2.2-3.el8                               BaseOS                                62 k Transaction Summary ===================================================================================================================================================================== Install  1 Package Total download size: 62 k Installed size: 18 k Downloading Packages: dnf-utils-4.0.2.2-3.el8.noarch.rpm                                                                                                    36 kB/s |  62 kB     00:01 --------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total                                                                                                                                 21 kB/s |  62 kB     00:03 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction   Preparing        :                                                                                                                                             1/1   Installing       : dnf-utils-4.0.2.2-3.el8.noarch                                                                                                              1/1   Running scriptlet: dnf-utils-4.0.2.2-3.el8.noarch                                                                                                              1/1   Verifying        : dnf-utils-4.0.2.2-3.el8.noarch                                                                                                              1/1 Installed:   dnf-utils-4.0.2.2-3.el8.noarch Complete!

Set up Docker stable repository

$ sudo yum-config-manager \     --add-repo \     https://download.docker.com/linux/centos/docker-ce.repo Adding repo from: https://download.docker.com/linux/centos/docker-ce.rep

Install Docker Engine – Community

Install specific version of Docker CE

As of now, Docker is not officially supported on CentOS/RHEL 8 because it has been replaced with Red Hat tools – buildah and podman. So if you try to install the latest version of Docker Community Edition, it will fail. What you can do is to check first which specific version of Docker is available for installation in your system, then go ahead with the actual installation. To find this out, issue below command:

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

Output

docker-ce.x86_64            3:19.03.5-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.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 Docker CE Stable - x86_64                        13 kB/s |  21 kB     00:01 Available Packages

All versions mentionned in above output are available to be installed. We will take one version randomly. Let’s say 3:18.09.1-3.el7. To install this version, parse “docker-ce:” before it, so the full version to install would be as below:

docker-ce-3:18.09.1-3.el7

Hence, the command to install this version will be:

$ sudo dnf install -y docker-ce-3:18.09.1-3.el7

Output

Last metadata expiration check: 0:12:17 ago on Sun 17 Nov 2019 02:13:31 PM +04. Dependencies resolved. =====================================================================================================================================================================  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.5-3.el7                                                  docker-ce-stable                   39 M Enabling module streams:  container-tools                                            rhel8 Transaction Summary ===================================================================================================================================================================== Install  5 Packages Total download size: 80 M Installed size: 338 M Downloading Packages: (1/5): container-selinux-2.94-1.git1e99f1d.module_el8.0.0+58+91b614e7.noarch.rpm                                                      16 kB/s |  43 kB     00:02 (2/5): libcgroup-0.41-19.el8.x86_64.rpm                                                                                               26 kB/s |  70 kB     00:02 (3/5): containerd.io-1.2.0-3.el7.x86_64.rpm                                                                                          5.2 MB/s |  22 MB     00:04 (4/5): docker-ce-18.09.1-3.el7.x86_64.rpm                                                                                            6.7 MB/s |  19 MB     00:02 (5/5): docker-ce-cli-19.03.5-3.el7.x86_64.rpm                                                                                        8.4 MB/s |  39 MB     00:04 --------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total                                                                                                                                7.0 MB/s |  80 MB     00:11 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.2 kB/s | 1.6 kB     00:01 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.5-3.el7.x86_64                                                                            1/5   Running scriptlet: docker-ce-cli-1:19.03.5-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+58+91b614e7.noarch                                         4/5   Running scriptlet: container-selinux-2:2.94-1.git1e99f1d.module_el8.0.0+58+91b614e7.noarch                                         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+58+91b614e7.noarch                                         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.5-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.5-3.el7.x86_64 Complete!
Install the latest version of Docker CE

Above method will install a specific version of Docker, but If you still want to install the latest version of Docker CE anyway, you can use the dnf command with the –nobest option to to use not only best candidate packages if the latest version installation does not work.

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

Output

Output $ sudo dnf -y install docker-ce --nobest Last metadata expiration check: 0:03:41 ago on Sun 17 Nov 2019 08:21:13 PM +04. Dependencies resolved.  Problem: package docker-ce-3:19.03.5-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.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  5 Packages Skip     1 Package Total download size: 80 M Installed size: 338 M Downloading Packages: (1/5): libcgroup-0.41-19.el8.x86_64.rpm                                                                                               40 kB/s |  70 kB     00:01 (2/5): container-selinux-2.94-1.git1e99f1d.module_el8.0.0+58+91b614e7.noarch.rpm                                                      25 kB/s |  43 kB     00:01 (3/5): containerd.io-1.2.0-3.el7.x86_64.rpm                                                                                          4.9 MB/s |  22 MB     00:04 (4/5): docker-ce-18.09.1-3.el7.x86_64.rpm                                                                                            6.1 MB/s |  19 MB     00:03 (5/5): docker-ce-cli-19.03.5-3.el7.x86_64.rpm                                                                                        8.1 MB/s |  39 MB     00:04 --------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total                                                                                                                                8.2 MB/s |  80 MB     00:09 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.2 kB/s | 1.6 kB     00:01 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.5-3.el7.x86_64                                                                                            1/5   Running scriptlet: docker-ce-cli-1:19.03.5-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+58+91b614e7.noarch                                                         4/5   Running scriptlet: container-selinux-2:2.94-1.git1e99f1d.module_el8.0.0+58+91b614e7.noarch                                                         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+58+91b614e7.noarch                                                         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.5-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.5-3.el7.x86_64 Skipped:   docker-ce-3:19.03.5-3.el7.x86_64 Complete!

Start and enable Docker

Docker is installed but is still not started. Let’s start and enable it.

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

Verify Docker CE installation

Run an alpine test container to check your Docker Engine CE installation

sudo docker run alpine [sudo] password for mourad: Unable to find image 'alpine:latest' locally latest: Pulling from library/alpine 89d9c30c1d48: Pull complete Digest: sha256:c19173c5ada610a5989151111163d28a67368362762534d8a8121ce95cf2bd5a Status: Downloaded newer image for alpine:latest

Add users to Docker group

We have installed and started Docker successfully. However, for any command that you need run in Docker, you will have to use your root privileges. In other words, you will need to use sudo to run Docker commands. This is because after Docker is installed, a new group called docker is created, which is the only object that has the privilege to run Docker commands.

Because no user is added to the group by default, you will have to explicitly make your user a member of this group If you want to use Docker as a non-root user.

$ sudo usermod -aG docker $(whoami)

Update docker group membership

$ sudo usermod -aG docker mourad 
$ id mourad uid=1000(mourad) gid=1000(mourad) groups=1000(mourad),10(wheel),986(docker) 

Run docker commands without sudo

$ docker run nginx Unable to find image 'nginx:latest' locally latest: Pulling from library/nginx Digest: sha256:922c815aa4df050d4df476e92daed4231f466acc8ee90e0e774951b0fd7195a4 Status: Downloaded newer image for nginx:latest

Remove Docker

If you’re done with your testing and want to remove docker binaries, use below command

$ sudo dnf remove docker-ce

This will remove docker from tour system but will not get rid of all images, containers, volumes, or customized configuration files created before. To do so, use below command

$ sudo rm -rf /var/lib/docker

Installing Docker using a Script

You can also gather all above commands in a bash script to make the installation easier.

Create a file and give it a name, for example docker-install.sh

$ touch docker-install.sh

Edit file with your preferred text editor and copy below script

#!/bin/bash
#
echo "Install required packages"
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
#
echo "Set up Docker stable repository"
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
#
echo "Install Docker Engine – Community"
sudo dnf -y install docker-ce --nobest
#
echo "Start and enable Docker"
sudo systemctl start docker && sudo systemctl enable docker
#
echo "Add current user to Docker group"
sudo usermod -aG docker $(whoami)
#
echo "Update group membership"
newgrp docker
#
echo "Docker installed successfully. Thanks!"

Lastly, make the file executable to be able to run it

chmod 770 install-docker.sh

Leave a Comment

Your email address will not be published. Required fields are marked *