How to Install Docker CE in Linux CentOS 7

Posted on

Introduction

This article will discuss about how to install Docker Community Edition (CE) or Docker CE in Linux CentOS 7. The way for installing Docker CE in Linux CentOS 7 is using yum package manager tool. The reason for using the yum package manager tool is because using the ‘curl’ command directly to process the installer to the shell command is not working. The following is an attempt to install it using the curl command feeding the installer to the shell script :

[root@localhost ~]# curl -fsSL https://get.docker.com/ | sh
curl: (6) Could not resolve host: get.docker.com; Unknown error
[root@localhost ~]# curl -fsSL http://get.docker.com/ | sh
curl: (6) Could not resolve host: get.docker.com; Unknown error
[root@localhost ~]#

The following installation step is using a reference from another article in this link. It is an article with the title of ‘Installing Docker Engine CE (Community Edition) on CentOS Linux 7’. Actually, the process to achieve it will be in several parts. The first part is the preparation part. Next part after will be the installation part. In the following after will be a part for just testing it.

Preparation Part

In this preparation part, it is actually important before the process for installing Docker CE using the yum package manager is possible, just do and execute several of the following things just to make sure :

  1. The first one is to check whether there are packages within the current installed repositories. Those are including duplicates in the package list with the name of ‘docker-ce’. Display it by sorting the output by executing the command below :

    [root@localhost ~]# yum list docker-ce --showduplicates | sort -r
    ....
    docker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-stable
    docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
    docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
    docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable
    docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable
    docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable
    docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable
    docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable
    docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable
    docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable
    docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable
    docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable
    docker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-stable
    docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
    docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
    docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
    * base: mirror.xxxxxxx.xxxxxx
    Available Packages
    [root@localhost ~]#
  2. Next, just execute the following command in order to remove the package associated with docker. Make sure to check first that it is not available. If it is exist and running properly, just use the already exist one. But if it is not, just to make sure that no other package with that name exist or available in the operating system type the following command :

    [root@localhost ~]# yum remove docker docker-common docker-selinux docker-engine
    Loaded plugins: fastestmirror
    No Match for argument: docker
    No Match for argument: docker-common
    No Match for argument: docker-selinux
    No Match for argument: docker-engine
    No Packages marked for removal
    [root@localhost ~]#
    [root@localhost ~]#
    [root@localhost ~]#
    
  3. Following after, just install some packages below which has some sort of role for Docker CE to run properly :

    [root@localhost ~]# sudo yum install -y yum-utils device-mapper-persistent-data lvm2
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    * base: mirror.xxxxxxx.xxxxxx
    * extras: mirror.xxxxxxx.xxxxxx
    * updates: mirror.xxxxxxx.xxxxxx
    Package yum-utils-1.1.31-54.el7_8.noarch already installed and latest version
    Resolving Dependencies
    --> Running transaction check
    ---> Package device-mapper-persistent-data.x86_64 0:0.8.5-3.el7_9.2 will be installed
    --> Processing Dependency: libaio.so.1(LIBAIO_0.4)(64bit) for package: device-mapper-persistent-data-0.8.5-3.el7_9.2.x86_64
    --> Processing Dependency: libaio.so.1(LIBAIO_0.1)(64bit) for package: device-mapper-persistent-data-0.8.5-3.el7_9.2.x86_64
    --> Processing Dependency: libaio.so.1()(64bit) for package: device-mapper-persistent-data-0.8.5-3.el7_9.2.x86_64
    ---> Package lvm2.x86_64 7:2.02.187-6.el7_9.5 will be installed
    --> Processing Dependency: lvm2-libs = 7:2.02.187-6.el7_9.5 for package: 7:lvm2-2.02.187-6.el7_9.5.x86_64
    --> Processing Dependency: liblvm2app.so.2.2(Base)(64bit) for package: 7:lvm2-2.02.187-6.el7_9.5.x86_64
    --> Processing Dependency: libdevmapper-event.so.1.02(Base)(64bit) for package: 7:lvm2-2.02.187-6.el7_9.5.x86_64
    --> Processing Dependency: liblvm2app.so.2.2()(64bit) for package: 7:lvm2-2.02.187-6.el7_9.5.x86_64
    --> Processing Dependency: libdevmapper-event.so.1.02()(64bit) for package: 7:lvm2-2.02.187-6.el7_9.5.x86_64
    --> Running transaction check
    ---> Package device-mapper-event-libs.x86_64 7:1.02.170-6.el7_9.5 will be installed
    ---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed
    ---> Package lvm2-libs.x86_64 7:2.02.187-6.el7_9.5 will be installed
    --> Processing Dependency: device-mapper-event = 7:1.02.170-6.el7_9.5 for package: 7:lvm2-libs-2.02.187-6.el7_9.5.x86_64
    --> Running transaction check
    ---> Package device-mapper-event.x86_64 7:1.02.170-6.el7_9.5 will be installed
    --> Finished Dependency Resolution
    Dependencies Resolved
    ============================================================================================================================================================================
    Package Arch Version Repository Size
    ============================================================================================================================================================================
    Installing:
    device-mapper-persistent-data x86_64 0.8.5-3.el7_9.2 updates 423 k
    lvm2 x86_64 7:2.02.187-6.el7_9.5 updates 1.3 M
    Installing for dependencies:
    device-mapper-event x86_64 7:1.02.170-6.el7_9.5 updates 192 k
    device-mapper-event-libs x86_64 7:1.02.170-6.el7_9.5 updates 192 k
    libaio x86_64 0.3.109-13.el7 base 24 k
    lvm2-libs x86_64 7:2.02.187-6.el7_9.5 updates 1.1 M
    Transaction Summary
    ============================================================================================================================================================================
    Install 2 Packages (+4 Dependent packages)
    Total download size: 3.2 M
    Installed size: 8.1 M
    Downloading packages:
    (1/6): device-mapper-event-1.02.170-6.el7_9.5.x86_64.rpm | 192 kB 00:00:03
    (2/6): device-mapper-event-libs-1.02.170-6.el7_9.5.x86_64.rpm | 192 kB 00:00:03
    (3/6): device-mapper-persistent-data-0.8.5-3.el7_9.2.x86_64.rpm | 423 kB 00:00:00
    (4/6): lvm2-2.02.187-6.el7_9.5.x86_64.rpm | 1.3 MB 00:00:00
    (5/6): libaio-0.3.109-13.el7.x86_64.rpm | 24 kB 00:00:00
    (6/6): lvm2-libs-2.02.187-6.el7_9.5.x86_64.rpm | 1.1 MB 00:00:00
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Total 882 kB/s | 3.2 MB 00:00:03
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
    Installing : 7:device-mapper-event-libs-1.02.170-6.el7_9.5.x86_64 1/6
    Installing : libaio-0.3.109-13.el7.x86_64 2/6
    Installing : device-mapper-persistent-data-0.8.5-3.el7_9.2.x86_64 3/6
    Installing : 7:device-mapper-event-1.02.170-6.el7_9.5.x86_64 4/6
    Installing : 7:lvm2-libs-2.02.187-6.el7_9.5.x86_64 5/6
    Installing : 7:lvm2-2.02.187-6.el7_9.5.x86_64 6/6
    Verifying : 7:device-mapper-event-1.02.170-6.el7_9.5.x86_64 1/6
    Verifying : 7:lvm2-libs-2.02.187-6.el7_9.5.x86_64 2/6
    Verifying : device-mapper-persistent-data-0.8.5-3.el7_9.2.x86_64 3/6
    Verifying : libaio-0.3.109-13.el7.x86_64 4/6
    Verifying : 7:lvm2-2.02.187-6.el7_9.5.x86_64 5/6
    Verifying : 7:device-mapper-event-libs-1.02.170-6.el7_9.5.x86_64 6/6
    Installed:
    device-mapper-persistent-data.x86_64 0:0.8.5-3.el7_9.2 lvm2.x86_64 7:2.02.187-6.el7_9.5
    Dependency Installed:
    device-mapper-event.x86_64 7:1.02.170-6.el7_9.5 device-mapper-event-libs.x86_64 7:1.02.170-6.el7_9.5 libaio.x86_64 0:0.3.109-13.el7 lvm2-libs.x86_64 7:2.02.187-6.el7_9.5
    Complete!
    [root@localhost ~]#
    
  4. After that, just try to add the Docker CE repository to the operating system by typing the following command :

    [root@localhost ~]# sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    Loaded plugins: fastestmirror
    adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
    grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
    repo saved to /etc/yum.repos.d/docker-ce.repo
    [root@localhost ~]#
    

Installation Step

So, the previous part is focusing on the preparation step for installing Docker CE. This part will just show the part for the installation of Docker CE. After successfully adding the necessary repository, just install the Docker CE by executing a command. Basically, just execute one single command to do it as follows :

[root@localhost ~]# sudo yum install docker-ce
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.xxxxxxx.xxxxxx
* extras: mirror.xxxxxxx.xxxxxx
* updates: mirror.xxxxxxx.xxxxxx
docker-ce-stable | 3.5 kB 00:00:00
(1/2): docker-ce-stable/7/x86_64/updateinfo | 55 B 00:00:00
(2/2): docker-ce-stable/7/x86_64/primary_db | 67 kB 00:00:01
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 3:20.10.10-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: 3:docker-ce-20.10.10-3.el7.x86_64
--> Processing Dependency: containerd.io >= 1.4.1 for package: 3:docker-ce-20.10.10-3.el7.x86_64
--> Processing Dependency: docker-ce-cli for package: 3:docker-ce-20.10.10-3.el7.x86_64
--> Processing Dependency: docker-ce-rootless-extras for package: 3:docker-ce-20.10.10-3.el7.x86_64
--> Running transaction check
---> Package container-selinux.noarch 2:2.119.2-1.911c772.el7_8 will be installed
---> Package containerd.io.x86_64 0:1.4.11-3.1.el7 will be installed
---> Package docker-ce-cli.x86_64 1:20.10.10-3.el7 will be installed
--> Processing Dependency: docker-scan-plugin(x86-64) for package: 1:docker-ce-cli-20.10.10-3.el7.x86_64
---> Package docker-ce-rootless-extras.x86_64 0:20.10.10-3.el7 will be installed
--> Processing Dependency: fuse-overlayfs >= 0.7 for package: docker-ce-rootless-extras-20.10.10-3.el7.x86_64
--> Processing Dependency: slirp4netns >= 0.4 for package: docker-ce-rootless-extras-20.10.10-3.el7.x86_64
--> Running transaction check
---> Package docker-scan-plugin.x86_64 0:0.9.0-3.el7 will be installed
---> Package fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 will be installed
--> Processing Dependency: libfuse3.so.3(FUSE_3.2)(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
--> Processing Dependency: libfuse3.so.3(FUSE_3.0)(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
--> Processing Dependency: libfuse3.so.3()(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
---> Package slirp4netns.x86_64 0:0.4.3-4.el7_8 will be installed
--> Running transaction check
---> Package fuse3-libs.x86_64 0:3.6.1-4.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
============================================================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================================================
Installing:
docker-ce x86_64 3:20.10.10-3.el7 docker-ce-stable 23 M
Installing for dependencies:
container-selinux noarch 2:2.119.2-1.911c772.el7_8 extras 40 k
containerd.io x86_64 1.4.11-3.1.el7 docker-ce-stable 28 M
docker-ce-cli x86_64 1:20.10.10-3.el7 docker-ce-stable 29 M
docker-ce-rootless-extras x86_64 20.10.10-3.el7 docker-ce-stable 8.0 M
docker-scan-plugin x86_64 0.9.0-3.el7 docker-ce-stable 3.7 M
fuse-overlayfs x86_64 0.7.2-6.el7_8 extras 54 k
fuse3-libs x86_64 3.6.1-4.el7 extras 82 k
slirp4netns x86_64 0.4.3-4.el7_8 extras 81 k
Transaction Summary
============================================================================================================================================================================
Install 1 Package (+8 Dependent packages)
Total download size: 93 M
Installed size: 376 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/containerd.io-1.4.11-3.1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY MB 00:00:02 ETA
Public key for containerd.io-1.4.11-3.1.el7.x86_64.rpm is not installed
(1/9): containerd.io-1.4.11-3.1.el7.x86_64.rpm | 28 MB 00:00:00
(2/9): docker-ce-20.10.10-3.el7.x86_64.rpm | 23 MB 00:00:01
(3/9): docker-ce-rootless-extras-20.10.10-3.el7.x86_64.rpm | 8.0 MB 00:00:00
(4/9): docker-scan-plugin-0.9.0-3.el7.x86_64.rpm | 3.7 MB 00:00:00
(5/9): docker-ce-cli-20.10.10-3.el7.x86_64.rpm | 29 MB 00:00:00
(6/9): container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm | 40 kB 00:00:01
(7/9): fuse3-libs-3.6.1-4.el7.x86_64.rpm | 82 kB 00:00:01
(8/9): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm | 54 kB 00:00:08
(9/9): slirp4netns-0.4.3-4.el7_8.x86_64.rpm | 81 kB 00:00:08
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 9.5 MB/s | 93 MB 00:00:09
Retrieving key from https://download.docker.com/linux/centos/gpg
Importing GPG key 0x621E9F35:
Userid : "Docker Release (CE rpm) <[email protected]>"
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.119.2-1.911c772.el7_8.noarch 1/9
Installing : containerd.io-1.4.11-3.1.el7.x86_64 2/9
Installing : 1:docker-ce-cli-20.10.10-3.el7.x86_64 3/9
Installing : docker-scan-plugin-0.9.0-3.el7.x86_64 4/9
Installing : fuse3-libs-3.6.1-4.el7.x86_64 5/9
Installing : fuse-overlayfs-0.7.2-6.el7_8.x86_64 6/9
Installing : slirp4netns-0.4.3-4.el7_8.x86_64 7/9
Installing : 3:docker-ce-20.10.10-3.el7.x86_64 8/9
Installing : docker-ce-rootless-extras-20.10.10-3.el7.x86_64 9/9
Verifying : docker-ce-rootless-extras-20.10.10-3.el7.x86_64 1/9
Verifying : docker-scan-plugin-0.9.0-3.el7.x86_64 2/9
Verifying : 3:docker-ce-20.10.10-3.el7.x86_64 3/9
Verifying : fuse-overlayfs-0.7.2-6.el7_8.x86_64 4/9
Verifying : containerd.io-1.4.11-3.1.el7.x86_64 5/9
Verifying : slirp4netns-0.4.3-4.el7_8.x86_64 6/9
Verifying : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 7/9
Verifying : fuse3-libs-3.6.1-4.el7.x86_64 8/9
Verifying : 1:docker-ce-cli-20.10.10-3.el7.x86_64 9/9
Installed:
docker-ce.x86_64 3:20.10.10-3.el7
Dependency Installed:
container-selinux.noarch 2:2.119.2-1.911c772.el7_8 containerd.io.x86_64 0:1.4.11-3.1.el7 docker-ce-cli.x86_64 1:20.10.10-3.el7
docker-ce-rootless-extras.x86_64 0:20.10.10-3.el7 docker-scan-plugin.x86_64 0:0.9.0-3.el7 fuse-overlayfs.x86_64 0:0.7.2-6.el7_8
fuse3-libs.x86_64 0:3.6.1-4.el7 slirp4netns.x86_64 0:0.4.3-4.el7_8
Complete!
[root@localhost ~]#

Testing Step

After successfully installing the Docker CE, just test it. Testing the Docker CE by doing the following execution of command :

  1. Following after, just try to execute the command for the installation.

    [root@localhost ~]# docker
    Usage: docker [OPTIONS] COMMAND
    A self-sufficient runtime for containers
    Options:
    --config string Location of client config files (default "/root/.docker")
    -c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and
    default context set with "docker context use")
    -D, --debug Enable debug mode
    -H, --host list Daemon socket(s) to connect to
    -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
    --tls Use TLS; implied by --tlsverify
    --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")
    --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
    --tlskey string Path to TLS key file (default "/root/.docker/key.pem")
    --tlsverify Use TLS and verify the remote
    -v, --version Print version information and quit
    Management Commands:
    app* Docker App (Docker Inc., v0.9.1-beta3)
    builder Manage builds
    buildx* Build with BuildKit (Docker Inc., v0.6.3-docker)
    config Manage Docker configs
    container Manage containers
    context Manage contexts
    image Manage images
    manifest Manage Docker image manifests and manifest lists
    network Manage networks
    node Manage Swarm nodes
    plugin Manage plugins
    scan* Docker Scan (Docker Inc., v0.9.0)
    secret Manage Docker secrets
    service Manage services
    stack Manage Docker stacks
    swarm Manage Swarm
    system Manage Docker
    trust Manage trust on Docker images
    volume Manage volumes
    Commands:
    attach Attach local standard input, output, and error streams to a running container
    build Build an image from a Dockerfile
    commit Create a new image from a container's changes
    cp Copy files/folders between a container and the local filesystem
    create Create a new container
    diff Inspect changes to files or directories on a container's filesystem
    events Get real time events from the server
    exec Run a command in a running container
    export Export a container's filesystem as a tar archive
    history Show the history of an image
    images List images
    import Import the contents from a tarball to create a filesystem image
    info Display system-wide information
    inspect Return low-level information on Docker objects
    kill Kill one or more running containers
    load Load an image from a tar archive or STDIN
    login Log in to a Docker registry
    logout Log out from a Docker registry
    logs Fetch the logs of a container
    pause Pause all processes within one or more containers
    port List port mappings or a specific mapping for the container
    ps List containers
    pull Pull an image or a repository from a registry
    push Push an image or a repository to a registry
    rename Rename a container
    restart Restart one or more containers
    rm Remove one or more containers
    rmi Remove one or more images
    run Run a command in a new container
    save Save one or more images to a tar archive (streamed to STDOUT by default)
    search Search the Docker Hub for images
    start Start one or more stopped containers
    stats Display a live stream of container(s) resource usage statistics
    stop Stop one or more running containers
    tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
    top Display the running processes of a container
    unpause Unpause all processes within one or more containers
    update Update configuration of one or more containers
    version Show the Docker version information
    wait Block until one or more containers stop, then print their exit codes
    Run 'docker COMMAND --help' for more information on a command.
    To get more help with docker, check out our guides at https://docs.docker.com/go/guides/
    [root@localhost ~]#
    
  2. Last but not least, in order to make sure, just execute the following command to check the docker version :

    [root@localhost ~]# docker version
    Client: Docker Engine - Community
    Version: 20.10.10
    API version: 1.41
    Go version: go1.16.9
    Git commit: b485636
    Built: Mon Oct 25 07:44:50 2021
    OS/Arch: linux/amd64
    Context: default
    Experimental: true
    Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
    [root@localhost ~]#
    

Leave a Reply