How to Install Docker on CentOS 7 / RHEL 7


Docker is a container virtualization technology that has gained widespread popularity in recent times; it offers a more efficient way to deploy the application. With Docker, the applications reside inside the container on top of the Linux operating system.

Docker uses Kernel features such as cgroups and namespace to allow an independent container to run on single os instance.

In this post, you will learn how to install Docker on CentOS 7 / RHEL 7.

Docker runs only on 64-bit operating system.
First, install the required packages.
# yum -y install lvm2 device-mapper device-mapper-persistent-data device-mapper-event device-mapper-libs device-mapper-event-libs

Install Docker

Choose any one of the methods to install Docker on CentOS 7.

Install from Docker (Official)

Docker is now available in two editions,

  • Community Edition (CE)
  • Enterprise Edition (EE)

Here, we will install Docker Comunity Edition (CE).

Uninstall older versions of Dockers, named “docker” or “docker-engine” along with associated dependencies.

# yum  -y remove  docker-common docker container-selinux docker-selinux docker-engine

Do not worry about the contents inside /var/lib/docker/, all will be preserved.

The Docker Comunity package is now called “docker-ce“. Let’s add the CE repository for docker installation.

# yum -y install  wget
# wget -O /etc/yum.repos.d/docker-ce.repo

Install the latest version of Docker CE using the following command.

# yum -y install docker-ce
Sometime you may want to install particular version of Docker, you do that by appending version like docker-ce-[version]
Eg: yum install docker-ce-17.03.0.ce-1.el7.centos

Install Docker from Base Repository

Docker is available in the standard repository of CentOS, so we don’t have to search for the package. For RHEL 7, you must have a valid Redhat subscription to enable Extras rpm’s repository on the server. Install it using the following command.

# yum -y install docker

Control Docker Service

Now you have Docker installed onto your machine, start the Docker service in case if it is not started automatically after the installation

# systemctl start docker

# systemctl enable docker

Once the service is started, verify your installation by running the following command.

# docker run -it centos echo Hello-World

Let’s see what happens when we run “docker run” command. Docker starts a container with centos base image since we are running this centos container for the first time, the output will look like below.

Unable to find image 'centos:latest' locally
Trying to pull repository ...
0114405f9ff1: Download complete
511136ea3c5a: Download complete
b6718650e87e: Download complete
3d3c8202a574: Download complete
Status: Downloaded newer image for

Docker looks for centos image locally, and it is not found, it starts downloading the centos image from Docker registry. Once the image has been downloaded, it will start the container and echo the command “Hello-World” in the console which you can see at the end of the output.

Allowing Non-root access

As you can see in my command, for CentOS, I had to run Docker as a root user. To avoid this, you can follow below procedure to allow non-root users to run Docker containers.

Create a group called docker if it does not exist, run the following commands with root privileges.

# groupadd docker

Add a user that is to be a part of docker group, replace “raj” with your own username.

# useradd raj

Add a user to docker group.

# usermod -aG docker raj

Now you can run a Docker with a non-root user.


FirwallD in CentOS 7 can conflict with Docker; it is recommended to disable the service.

# systemctl stop firewalld
# systemctl disable firewalld

When firewalld is started or restarted it will remove the DOCKER chain from iptables, it prevents Docker from working properly.

If you still want to use systemd, firewalld is must be started before Docker service. In case if you start or restart firewalld after Docker, you will have to restart the Docker daemon.

Interested Topics

Docker Basic Topics:

1: Top Important Docker Commands – Working with Docker Containers

2: Working with Docker Images – Building Docker Images

3: How to Build Docker Images with DockerFile

Docker Advanced Topics:

1: How to Setup Docker Private Registry on CentOS 7 / Ubuntu 16.04 / Fedora 27/26

2: How to Install and Configure Docker Swarm on CentOS 7 / Ubuntu 16.04 / Fedora 27/26

That’s All.

You might also like

How to Install Docker on CentOS 7 / RHEL 7