How to Install Docker on Redhat/CentOS 7

By | August 24, 2018

In this blog, we will see how to install Docker CE (Community Edition) in Redhat Enterprise Linux (RHEL 7) and CentOS 7. Please refer steps for installing Docker on ubuntu machine here. In the previous blog, we have tried to explain the basics of docker with the installation process. Here, We are not going to go in details with the docker concept and will directly move ahead with the installation process.

So let’s see how we can install docker in redhat/centos7.

Login to Rhel/Centos 7 machine and Update the repository.

[root@devopsage ~]# yum update -y

Docker package is by default available in the redhat/centos repository also like in Ubuntu, but it may not be the latest version available. To install the latest version of a docker, set up the official docker repository.

For Community Edition (Use this command)
[root@devopsage ~]# yum install yum-utils
[root@devopsage ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

(Optional) For Enterprise Edition

# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ee.repo

You can verify the repo file in /etc/yum.repos.d/ directory.

[root@devopsage ~]# cat /etc/yum.repos.d/docker-ce.repo

Also, Verify with,

[root@devopsage ~]# yum repolist

Now, Install dokcer-ce using below command,

[root@devopsage ~]# yum install docker-ce -y

Start the docker daemon

[root@devopsage ~]# systemctl start docker.service

Enable to run docker daemon to start on boot

[root@devopsage ~]# systemctl enable docker.service

Check whether the docker daemon is running or not

[root@devopsage ~]# systemctl status docker.service

● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2018-08-24 17:30:58 UTC; 19s ago
     Docs: https://docs.docker.com
 Main PID: 1938 (dockerd)
   CGroup: /system.slice/docker.service
           ├─1938 /usr/bin/dockerd
           └─1944 docker-containerd --config /var/run/docker/containerd/containerd.toml
     .
     .

Check docker version

[root@devopsage ~]# docker -v
Docker version 18.06.1-ce, build e68fc7a
[root@devopsage ~]# docker version
Client:
 Version:           18.06.1-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        e68fc7a
 Built:             Tue Aug 21 17:23:03 2018
 OS/Arch:           linux/amd64
 Experimental:      false
    .
    .

Also, check by executing docker command

[root@devopsage ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

Note: You may not be able to run the docker command as a normal user by default, you can run only by root user or using sudo privileges.

[testuser@devopsage ~]$ docker ps
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.38/containers/json: dial unix /var/run/docker.sock: connect: permission denied

To avoid this issue, you can either give full permission to docker.sock or put this user to the docker group.

testuser@devopsage:~$ sudo usermod testuser -aG docker  // Logout and login to that user and check

testuser@devopsage:~$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

OR, a Simple but not recommended method of solving this issue is to simply give full permission to docker.sock

root@devopsage:~# chmod 777 /var/run/docker.sock

You May Also Like!!
How to install Docker on Ubuntu 16.04

If you Like Our Content here at Devopsage, then please support us by sharing this post.

Please Like and follow us at, LinkedIn, Facebook, Twitter, and GitHub

Also, Please comment on the post with your views and let us know if any changes need to be done.

Thanks!!

Leave a Reply

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