How to Install Docker on CentOS 7

In our latest Docker tutorial, we told you about different mount types for Docker containers. In this tutorial, we will be helping you to install “Docker Community Edition (CE)” on CentOS 7 operating system. The procedure is the same for Red Hat Linux 7.

 

How to Install Docker on CentOS 7

 

Prerequisite to Install Docker

1. Already installed CentOS 7.

2. Knowledge about Linux command line.

3. Access to the Internet.

 

Now, let see how to install Docker on our CentOS or RHEL 7 server.

 

Steps to Install Docker on CentOS 7

 

1. First of all, verify that you don’t have Docker installed already using ‘rpm’ command

[root@cent-server ~]# rpm -qa | grep -i docker
[root@cent-server ~]#

If you any previous version of Docker installed and not needed now, you can uninstall it before starting the new installation.

 

2. Now, install the packages like “yum-utils device-mapper-persistent-data lvm2” which are very important and required for this task. yum-utils provides the yum-config-manager utility, and device-mapper-persistent-data and lvm2 are required by the ‘device mapper’ storage driver.

[root@cent-server ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                              |  16 kB  00:00:00
 * base: centos.mirror.globo.tech
 * epel: mirror.dst.ca
 * extras: centos.mirror.globo.tech
 * updates: centos.mirror.ca.planethoster.net
base                                                              | 3.6 kB  00:00:00
extras                                                            | 2.9 kB  00:00:00
updates                                                           | 2.9 kB  00:00:00
Resolving Dependencies
--> Running transaction check
---> Package device-mapper-persistent-data.x86_64 0:0.7.3-3.el7 will be updated
---> Package device-mapper-persistent-data.x86_64 0:0.8.5-1.el7 will be an update
---> Package lvm2.x86_64 7:2.02.180-10.el7_6.8 will be updated
---> Package lvm2.x86_64 7:2.02.185-2.el7 will be an update
--> Processing Dependency: lvm2-libs = 7:2.02.185-2.el7 for package: 7:lvm2-2.02.185-2.el7.x86_64
---> Package yum-utils.noarch 0:1.1.31-50.el7 will be updated
---> Package yum-utils.noarch 0:1.1.31-52.el7 will be an update
...............................................
...............................................
Output Truncated
...............................................
...............................................
  Verifying  : 7:device-mapper-event-1.02.149-10.el7_6.8.x86_64          15/16
  Verifying  : 7:device-mapper-1.02.149-10.el7_6.8.x86_64                16/16

Updated:
  device-mapper-persistent-data.x86_64 0:0.8.5-1.el7                  lvm2.x86_64 7:2.02.185-2.el7                  yum-utils.noarch 0:1.1.31-52.el7

Dependency Updated:
  device-mapper.x86_64 7:1.02.158-2.el7               device-mapper-event.x86_64 7:1.02.158-2.el7          device-mapper-event-libs.x86_64 7:1.02.158-2.el7
  device-mapper-libs.x86_64 7:1.02.158-2.el7          lvm2-libs.x86_64 7:2.02.185-2.el7

Complete!

 

3. Enable the edge and test repositories. These repositories are included in the docker.repo file above but are disabled by default. You can enable them alongside the stable repository if you want.

[root@cent-server ~]# yum-config-manager --enable docker-ce-edge
[root@cent-server ~]# yum-config-manager --enable docker-ce-test

You can now list the total available packages with the help of “yum repolist” command.

[root@cent-server ~]# yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: rep-centos-ca.upress.io
 * epel: mirror.dst.ca
 * extras: centos.mirror.globo.tech
 * updates: centos.mirror.ca.planethoster.net
docker-ce-edge                                                                                  | 3.5 kB  00:00:00
docker-ce-stable                                                                                | 3.5 kB  00:00:00
docker-ce-test                                                                                  | 3.5 kB  00:00:00
(1/2): docker-ce-test/x86_64/updateinfo                                                         |   55 B  00:00:00
(2/2): docker-ce-test/x86_64/primary_db                                                         | 104 kB  00:00:00
repo id                                       repo name                                                          status
base/7/x86_64                                 CentOS-7 - Base                                                    10,097
docker-ce-edge/x86_64                         Docker CE Edge - x86_64                                                61
docker-ce-stable/x86_64                       Docker CE Stable - x86_64                                              56
docker-ce-test/x86_64                         Docker CE Test - x86_64                                               185
epel/x86_64                                   Extra Packages for Enterprise Linux 7 - x86_64                     13,426
extras/7/x86_64                               CentOS-7 - Extras                                                     304
updates/7/x86_64                              CentOS-7 - Updates                                                    332
repolist: 24,461

 

4. Now it’s time to install the Docker CE package through above configured repositories.

[root@cent-server ~]# yum install docker-ce
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.mirror.globo.tech
 * epel: mirror.dst.ca
 * extras: centos.mirror.globo.tech
 * updates: centos.bhs.mirrors.ovh.net
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 3:19.03.3-2.1.rc1.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: 3:docker-ce-19.03.3-2.1.rc1.el7.x86_64
--> Processing Dependency: containerd.io >= 1.2.2-3 for package: 3:docker-ce-19.03.3-2.1.rc1.el7.x86_64
--> Processing Dependency: docker-ce-cli for package: 3:docker-ce-19.03.3-2.1.rc1.el7.x86_64
--> Running transaction check
---> Package container-selinux.noarch 2:2.107-3.el7 will be installed
---> Package containerd.io.x86_64 0:1.2.6-3.3.el7 will be installed
---> Package docker-ce-cli.x86_64 1:19.03.3-2.1.rc1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================================================
 Package                                   Arch                           Version                                       Repository                              Size
=====================================================================================================================================================================
Installing:
 docker-ce                                 x86_64                         3:19.03.3-2.1.rc1.el7                         docker-ce-test                          24 M
Installing for dependencies:
 container-selinux                         noarch                         2:2.107-3.el7                                 extras                                  39 k
 containerd.io                             x86_64                         1.2.6-3.3.el7                                 docker-ce-edge                          26 M
 docker-ce-cli                             x86_64                         1:19.03.3-2.1.rc1.el7                         docker-ce-test                          39 M

Transaction Summary
=====================================================================================================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 90 M
Installed size: 369 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): container-selinux-2.107-3.el7.noarch.rpm                                                                                               |  39 kB  00:00:00
warning: /var/cache/yum/x86_64/7/docker-ce-edge/packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY 00:00:03 ETA
Public key for containerd.io-1.2.6-3.3.el7.x86_64.rpm is not installed
(2/4): containerd.io-1.2.6-3.3.el7.x86_64.rpm                                                                                                 |  26 MB  00:00:05
Public key for docker-ce-19.03.3-2.1.rc1.el7.x86_64.rpm is not installed[=========================================                 ] 9.7 MB/s |  64 MB  00:00:02 ETA
(3/4): docker-ce-19.03.3-2.1.rc1.el7.x86_64.rpm                                                                                               |  24 MB  00:00:06
(4/4): docker-ce-cli-19.03.3-2.1.rc1.el7.x86_64.rpm                                                                                           |  39 MB  00:00:08
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                 10 MB/s |  90 MB  00:00:08
Retrieving key from https://download.docker.com/linux/centos/gpg
Importing GPG key 0x621E9F35:
 Userid     : "Docker Release (CE rpm) "
 Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
 From       : https://download.docker.com/linux/centos/gpg
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 2:container-selinux-2.107-3.el7.noarch                 1/4
  Installing : containerd.io-1.2.6-3.3.el7.x86_64                     2/4
  Installing : 1:docker-ce-cli-19.03.3-2.1.rc1.el7.x86_64             3/4
  Installing : 3:docker-ce-19.03.3-2.1.rc1.el7.x86_64                 4/4
  Verifying  : 3:docker-ce-19.03.3-2.1.rc1.el7.x86_64                 1/4
  Verifying  : 1:docker-ce-cli-19.03.3-2.1.rc1.el7.x86_64             2/4
  Verifying  : 2:container-selinux-2.107-3.el7.noarch                 3/4
  Verifying  : containerd.io-1.2.6-3.3.el7.x86_64                     4/4

Installed:
  docker-ce.x86_64 3:19.03.3-2.1.rc1.el7

Dependency Installed:
  container-selinux.noarch 2:2.107-3.el7                containerd.io.x86_64 0:1.2.6-3.3.el7                docker-ce-cli.x86_64 1:19.03.3-2.1.rc1.el7

Complete!

 

5. Once Docker package is installed, you can verify it by using ‘rpm’ command or ‘docker –version’ command.

[root@cent-server ~]# rpm -qa |grep -i dock
docker-ce-cli-19.03.3-2.1.rc1.el7.x86_64
docker-ce-19.03.3-2.1.rc1.el7.x86_64
[root@cent-server ~]#
[root@cent-server ~]# docker --version
Docker version 19.03.3-rc1, build 1576bd7917

 

6. Now its time to start Docker and enable it using systemctl command.

[root@cent-server ~]# systemctl start docker
[root@cent-server ~]#
[root@cent-server ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@cent-server ~]#

 

7. Test Docker by running the most common hello-world image. It will take some time to download the hello-world image for the first time.

[root@cent-server ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:b8ba256769a0ac28dd126d584e0a2011cd2877f3f76e093a7ae560f2a5301c00
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

[root@cent-server ~]#

 

This is it!


You have installed ‘Docker CE’ now, its time to play around and run some images and try containers.

We hope you liked this basic Docker tutorial and know how to install Docker on CentOS 7 Linux. If you have any doubts or facing any problems, just let us know through your comments. Also, do not forget to share this article with your friends and colleague.

Buy me a coffeeBuy me a coffee

Add Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.