decorative image for blog on installing docker on centos
November 11, 2020

How to Install Docker on CentOS

Containers
Operating Systems

Docker has quickly become the most popular program for containerization. For CentOS users, that means an increase in the need to install Docker on CentOS. Luckily, the process for CentOS Docker installation on CentOS 6, CentOS 7CentOS 8, and CentOS Stream is fairly simple.

In this blog, we’ll look at how to install Docker on CentOS 6, 7, 8, and Stream, then look at some Docker basics that can help you to get started.

Back to top

What Is Docker?

Docker is a program for building, running, and managing containers.

Containers are run as namespaces under the linux kernel, and are implemented with images that contain the filesystems and all data needed to run the process in the container. This mostly separates the running process from other resources on the system.

This is simplified, of course, because this article isn’t really about what Docker is and how to use it, but how to achieve a successful CentOS Docker installation.

Back to top

CentOS Docker Installation Guide

Installing Docker on CentOS varies from version to version. Below you’ll find instructions on how to install Docker on CentOS versions 6, 7, and 8.

How to Install Docker on CentOS 6

CentOS 6 will reach end of life on November 30, 2020, so there will be no more updates. Docker CE is not available for CentOS 6. The best we can do is install an old version from docker.com, which is version 1.7.0-1:

yum install -y https://get.docker.com/rpm/1.7.0/centos-6/RPMS/x86_64/docker-engine-1.7.0-1.el6.x86_64.rpm

However, CentOS 6 is no longer recommended since it will no longer receive security fixes or updates.

How to Install Docker on CentOS 7

The default docker version (with CentOS 7) is 2:1.13.1-162git64e9980, which is quite old. We will install the latest version from main docker repository. First we install yum-utils, which gives a command for easily adding repositories. Then we use that command to add the docker repo, then install docker-ce:

yum install -y yum-utils 
yum-config-manager --add-repo
https://download.docker.com/linux/centos/docker-ce.repo 
yum install -y docker-ce

The version installed on my test CentOS 7 instance is docker-ce-19.03.13-3 .

How to Install Docker on CentOS 8

Centos 8 installs podman by default. It is nearly a drop-in replacement for docker, that doesn’t use a service to run. However we are not covering podman in this article, so we will remove it to install docker. DNF is a replacement for yum. Yum is an alternate name for dnf in CentOS 8.

dnf remove -y podman buildah
# This is the same as dnf-utils, this may already be installed
dnf install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
dnf install -y docker-ce

How to Install Docker on CentOS Stream

To install Docker on CentOS Stream 8, follow the same process outlined above. Remove podman, install yum, then install docker.

dnf remove -y podman buildah
# This is the same as dnf-utils, this may already be installed
dnf install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
dnf install -y docker-ce

Back to top

Running Docker on CentOS

After you install Docker on CentOS, you're ready to run it. Docker uses some kernel modules, like the overlay fs module, so make sure your system has module loading enabled. Make sure the following option is set to 0:

kernel.modules_disabled = 0

Otherwise starting the docker service will fail. Then you can start docker and make sure it starts at boot time.

On CentOS 7/8:

systemctl start docker
systemctl enable docker
systemctl status docker

On CentOS 6:

chkconfig docker
service docker start
service docker status

Setting Docker Permissions in CentOS

By default only root can run docker commands. To allow users other than root to run docker, add them to the docker group:

usermd -G docker -a loginid 

This will add the user to the docker group. The -a option appends the group, instead of replacing the groups. Test by running a simple hello-world app:

docker run hello-world

Back to top

Using Docker Commands in CentOS

To show some commands, we will run a simple container that stays running until you stop it. In one shell, type:

docker run -p 80:80 nginx

That says to run the nginx container (a web server) and map port 80 on the host to port 80 in the container. You will see some ouput, then:

/docker-entrypoint.sh: Configuration complete; ready for start up

In another shell, test with:

curl -v localhost

Also you will see a log entry for the nginx container. Show the containers running with docker ps:

#d50f34872cea inginx "/docker-entrypoint..." 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp crazy_heisenberg

If you don’t give a container a name, docker will give it a random name. You can reference a container with either the CONTAINER ID or the name.

docker logs crazy_heisenberg

Docker logs shows the log information, which was also printed to the terminal before. docker inspect will show lots of internal information about the container.

Back to top

Need to Move off CentOS?

OpenLogic can help. With support for top open source Enterprise Linux distributions -- like Rocky Linux and AlmaLinux -- OpenLogic can help you maximize stability for your deployments and ensure ongoing success for your enterprise systems. 

Learn more about we can offer your team by downloading our datasheet or visiting our Enterprise Linux support page below.

Enterprise Linux Support

Back to top

 Concerned About Changes to CentOS?

In our latest webinar, Perforce OSS Evangelist Javier Perez details the changes to CentOS, how they impact organizations using CentOS, and what to do next if you are impacted.

Additional Resources

Looking for additional resources on popular open source containerization technologies? Be sure to look at these options from our open source experts:

Back to top