How to Install Docker on CentOS 8

December 27, 2019

Introduction

The new CentOS 8 release has introduced many innovative elements compared to its predecessor. Our recent article provides an in-depth analysis of the new and improved features of CentOS 8.

One significant change is the decision to no longer provide official support for Docker. Instead, RHE has opted to introduce in-built tools for container image creation and management: buildah and podman. These tools are compatible with Docker but don’t need a server/client architecture to run.

In case you are still not ready to use these new tools just yet, this tutorial will explain how to install Docker on CentOS 8.

logos on docker installation tutorial for CentOS 8

Prerequisites

Important: Disabling critical security features is not encouraged. However, the firewalld manager in CentOS 8 prevents DNS resolution within Docker containers. This tutorial contains instructions on how to disable firewalld.

Add Docker Repository Using DNF

CentOS 8 uses the YUM package manager version v4.0.4. This version now uses DNF (Dandified YUM).

DNF is a software package manager. It installs, performs updates, and removes packages on Linux distributions.

Note: CentOS 8 has a much-improved software management system. DNF technology provides increased performance, has well-defined APIs, and supports modular content, software AppStreams for cloud, container workloads, and CI/CD.

Use DNF to add and enable the official Docker CE repository. Type the following command in your terminal window:

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

The system informs you that it has successfully retrieved the repository.

Terminal confirms Docker is added to CentOS 8.
sudo dnf repolist -v

The onscreen information provides all relevant details.

verifying the correct repository was added

To list all the available docker-ce packages, type:

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

Unfortunately, CentOS 8 does not support specific versions of the container.id package. This means that only some versions of docker-ce are available for installation.

A list of docker-ce versions available for installation on system

There are two ways to address this issue and install Docker on CentOS 8.

Install Docker CE on CentOS 8

Option 1: Skip Packages with Broken Dependencies

An efficient solution is to allow your CentOS 8 system to install the version that meets the criteria best, using the --nobest command:

sudo dnf install docker-ce --nobest

The installation skips the latest candidates and installs the most appropriate version with the required containerd.io packages.

Installing docker ce with the nobest command

Once you confirm by entering y, the system proceeds to install Docker CE 18.06.3.ce-3.el7.

Installation skipped the latest version

If you look closely, you will see that the installation skipped the latest version of docker-ce as it did not meet the criteria.

Option 2: Install containerd.io Package Manually

Another option for installing Docker on CenOS 8 is to install the containerd.io package manually, in advance. This workaround allows you to install the latest docker-ce version.

Use the following command:

sudo dnf install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.10-3.2.el7.x86_64.rpm

Confirm the installation with y. You have successfully installed the latest version of containerd.io.

Latest version of containerd.io installed sucessfully

Now we can proceed to install the latest version of docker-ce with a simple command:

sudo dnf install docker-ce -y

The output below confirms that docker-ce-3:19.03.5-3.el7.x86_64 has been successfully installed.

Latest version of Docker CE installed

Start and Test Docker

Enable Docker

Enable and start the Docker service with:

sudo systemctl enable --now docker

The output confirms that we have created a symlink.

Enabling Docker on CentOS 8

Next, use this short command to confirm that Docker is active and running:

systemctl status docker

We see the timestamp and confirm that Docker is active.

Docker active and running confirmation on CentOS

Add User to Docker User Group

Add your user to the docker group with the following command:

sudo usermod -aG docker $USER
id $USER

The system executes the commands.

Add user to Docker user group.

Disable firewalld on CentOS 8

As mentioned previously, we need to disable firewalld for DNS resolution inside Docker containers to work.

One simple command is enough to disable firewalld in CentOS 8:

sudo systemctl disable firewalld

The output confirms that the service has been disabled.

The system confirms that firewalld has been successfully disabled.

At this point, it is recommended to reboot your system for the change to take effect.

Testing Docker Installation by Pulling Test Container Image

Download a small alpine docker container image to test the installation:

docker pull alpine

The system downloads the latest version of the image.

Command to retrieve a basic alpine image using Docker on CentOS 8

Check if the image is available:

docker images

The system lists your Docker images:

Alpine image in Docker Repository

Initiate Alpine Container Image

Use Docker to run the container with the downloaded image and try doing a simple apk update:

docker run -it --rm alpine /bin/sh
/# apk update

The output confirms that the container has been initiated.

Alpine container successfully run on CentOS 8 docker installation.

You have successfully installed and configured Docker on CentOS 8.

Conclusion

By following this tutorial, you should now have a working Docker installation on CentOS 8.

The release of CentOS 8 includes many new features that raise the bar for RHEL-based operating systems and improves overall UX.

Was this article helpful?
YesNo
Vladimir Kaplarevic
Vladimir is a resident Tech Writer at phoenixNAP. He has more than 7 years of experience in implementing e-commerce and online payment solutions with various global IT services providers. His articles aim to instill a passion for innovative technologies in others by providing practical advice and using an engaging writing style.
Next you should read
How To Install and Use Docker on Ubuntu 20.04
April 6, 2023

Install Docker on Ubuntu 20.04 using the default repository or from the official Docker repository with the...
Read more
Docker Commands
December 7, 2022

Docker has earned a reputation as one of the most popular open-source platforms for application development...
Read more
How to Create Docker Image with Dockerfile
October 23, 2019

A Dockerfile offers a simpler and faster way of creating Docker images. They go through the script with all...
Read more
How to SSH into a Running Docker Container and Run Commands
October 24, 2019

This knowledge base article explains how to SSH into a running Docker container. Docker exec and docker...
Read more