You can install and use Docker on Centos7. In this article, we will go step by step instructions to do that. You need also Centos extras repository.

Prerequisites:

  • Enabling Centos Extras repo
  • Network Access to Centos, Centos Extras and Docker CE repositories
  • Sudo privilege or admin access to Centos7 server

If you can satisfy the prerequisites listed above then you can continue the instructions in this article, otherwise don’t waste your time 🙂

Docker recommends uninstalling the older version of Docker and its components from your server.

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

If you don’t have any package to uninstall then you will see “No Packages marked for removal” message. That is ok. After removing old packages we have to install other required packages.

sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

We can add the Docker Community Edition(docker ce) repository to our server. Enterprise edition requires a license and contains more features than the community edition.

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

If your server can reach the URL mentioned above it will save a copy of that file to /etc/yum.repos.d/docker-ce.repo in your server. After that, Now we can install Docker

sudo yum -y install docker-ce docker-ce-cli containerd.io

Now we have to enable and start the Docker daemon with the help of systemctl commands.

sudo systemctl enable docker
sudo systemctl start docker

If everything went well till now, you can check if the Docker daemon is started and working fine with systemctl status docker command like this

[root@server1 ~]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2020-03-15 12:52:46 CET; 3min 33s ago
     Docs: https://docs.docker.com
 Main PID: 3972 (dockerd)
    Tasks: 14
   Memory: 44.6M
   CGroup: /system.slice/docker.service
           └─3972 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Mar 15 12:52:46 server1.devopsmania.com dockerd[3972]: time="2020-03-15T12:52:46.530026558+01:00" level=info msg="scheme \"unix\" not r...e=grpc
Mar 15 12:52:46 server1.devopsmania.com dockerd[3972]: time="2020-03-15T12:52:46.530061240+01:00" level=info msg="ccResolverWrapper: se...e=grpc
Mar 15 12:52:46 server1.devopsmania.com dockerd[3972]: time="2020-03-15T12:52:46.530083658+01:00" level=info msg="ClientConn switching ...e=grpc
Mar 15 12:52:46 server1.devopsmania.com dockerd[3972]: time="2020-03-15T12:52:46.570437538+01:00" level=info msg="Loading containers: start."
Mar 15 12:52:46 server1.devopsmania.com dockerd[3972]: time="2020-03-15T12:52:46.835548791+01:00" level=info msg="Default bridge (docke...dress"
Mar 15 12:52:46 server1.devopsmania.com dockerd[3972]: time="2020-03-15T12:52:46.930071080+01:00" level=info msg="Loading containers: done."
Mar 15 12:52:46 server1.devopsmania.com dockerd[3972]: time="2020-03-15T12:52:46.956450753+01:00" level=info msg="Docker daemon" commit...9.03.8
Mar 15 12:52:46 server1.devopsmania.com dockerd[3972]: time="2020-03-15T12:52:46.956624627+01:00" level=info msg="Daemon has completed ...ation"
Mar 15 12:52:46 server1.devopsmania.com dockerd[3972]: time="2020-03-15T12:52:46.987356872+01:00" level=info msg="API listen on /var/ru....sock"
Mar 15 12:52:46 server1.devopsmania.com systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
[root@server1 ~]#

You can also check the status and connectivity towards Docker Hub with downloading the hello-world image and running it via following commands. docker version and docker container run hello-world

[root@server1 ~]# docker version
Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b
 Built:             Wed Mar 11 01:27:04 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.8
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       afacb8b
  Built:            Wed Mar 11 01:25:42 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
[root@server1 ~]#
[root@server1 ~]# docker container run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:f9dfddf63636d84ef479d645ab5885156ae030f611a56f3a7ac7f2fdd86d7e4e
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@server1 ~]#

If you are going to use Docker Hub images then you might need access to auth.docker.io, index.docker.io, registry-1.docker.io, *.docker.com sites. don’t forget to whitelist these targets at your proxy.

Let me know if you have any issues when installing Docker on Centos7.

Leave a Reply

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