February 28, 2021
How to install Docker CE on CentOS 8

How To Install Docker And Docker Compose On CentOS 8

On this article we will discuss how to install Docker Community Edition on CentOS 8.

Introduction

One of the significant change on CentOS 8 is no longer to provide official support for Docker, where CentOS 8 has the same function in-built tools for container image creation and management like Docker has, namely: buildah and podman. Otherwise, this article will show you how to install Docker Community Edition on CentOS 8.

The Docker installation on CentOS 8 article will be detailed up to several sub-topic as described below :

  1. Prerequisite
  2. Adding Docker Repository
  3. Install Docker CE on CentOS 8
  4. Start and Test Docker

Prerequisite

  • CentOS 8 system
  • User account with sudo privillege
  • Sufficient disk space and good network access to Docker source

Adding Docker Repository

Since CentOS 8 terminates the Docker support, we need to add an external repository to obtain the Docker software. In this case we will use the official Docker Community Edition (CE) CentOS repository. For this purpose we use the command line : dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo.

sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
[sudo] password for ramans:
Adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
Add Docker Repository to CentOS 8

To verify the Docker repository has been added to the CentOS 8 system, we will use the command line : dnf repolist -v.

[ramans@localhsost ~]$ sudo dnf repolist -v
Completion plugin: Generating completion cache…

Repo-id : AppStream
Repo-name : CentOS-8 - AppStream
Repo-revision : 8.2.2004
Repo-distro-tags : [cpe:/o:centos:centos:8]: , 8, C, O, S, e, n, t
Repo-updated : Fri 30 Oct 2020 10:58:38 AM PDT
Repo-pkgs : 5,365
Repo-available-pkgs: 4,920
Repo-size : 6.3 G
Repo-mirrors : http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=stock
Repo-baseurl : http://mirror.idroot.cloud/centos/8.2.2004/AppStream/x86_64/os/ (9 more)
Repo-expire : 172,800 second(s) (last: Sun 08 Nov 2020 11:56:43 PM PST)
Repo-filename : /etc/yum.repos.d/CentOS-AppStream.repo

Repo-id : BaseOS
Repo-name : CentOS-8 - Base
Repo-revision : 8.2.2004
Repo-distro-tags : [cpe:/o:centos:centos:8]: , 8, C, O, S, e, n, t
Repo-updated : Fri 30 Oct 2020 10:58:33 AM PDT
Repo-pkgs : 1,675
Repo-available-pkgs: 1,673
Repo-size : 1.0 G
Repo-mirrors : http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=BaseOS&infra=stock
Repo-baseurl : http://mirror.buana.web.id/centos/8.2.2004/BaseOS/x86_64/os/ (9 more)
Repo-expire : 172,800 second(s) (last: Sun 08 Nov 2020 11:56:45 PM PST)
Repo-filename : /etc/yum.repos.d/CentOS-Base.repo

Repo-id : docker-ce-stable
Repo-name : Docker CE Stable - x86_64
Repo-revision : 1600369427
Repo-updated : Thu 17 Sep 2020 12:03:47 PM PDT
Repo-pkgs : 3
Repo-available-pkgs: 3
Repo-size : 91 M
Repo-baseurl : https://download.docker.com/linux/centos/8/x86_64/stable
Repo-expire : 172,800 second(s) (last: Sun 08 Nov 2020 11:58:45 PM PST)
Repo-filename : /etc/yum.repos.d/docker-ce.repo

We have found if the docker-ce-stable has been added on the system.

Docker CE Stable repository

Install Docker CE on CentOS 8

After adding Docker CE repository, we will install it on the system, by submitting command line : dnf install docker-ce --nobest. We will use ‘–nobest‘ option to prevent the instaltation to allow CentOS 8 to install the most appropriate version for our needs.

[ramans@localhsost ~]$ sudo dnf install docker-ce --nobest
Last metadata expiration check: 0:01:04 ago on Sun 08 Nov 2020 11:58:45 PM PST.
Dependencies resolved.
Package Arch Version Repository Size
Installing:
docker-ce x86_64 3:19.03.13-3.el8 docker-ce-stable 24 M
Installing dependencies:
container-selinux noarch 2:2.124.0-1.module_el8.2.0+305+5e198a41 AppStream 47 k
containerd.io x86_64 1.3.7-3.1.el8 docker-ce-stable 29 M
docker-ce-cli x86_64 1:19.03.13-3.el8 docker-ce-stable 38 M
Enabling module streams:
container-tools rhel8
Transaction Summary
Install 4 Packages
Total download size: 91 M
Installed size: 385 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): container-selinux-2.124.0-1.module_el8.2.0+305+5e198a41.noarc 5.5 kB/s | 47 kB 00:08
[MIRROR] docker-ce-cli-19.03.13-3.el8.x86_64.rpm: Curl error (28): Timeout was reached for https://download.docker.com/linux/centos/8/x86_64/stable/Packages/docker-ce-cli-19.03.13-3.el8.x86_64.rpm [Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds]
(2/4): containerd.io-1.3.7-3.1.el8.x86_64.rpm 66 kB/s | 29 MB 07:27
(3/4): docker-ce-19.03.13-3.el8.x86_64.rpm 53 kB/s | 24 MB 07:41
(4/4): docker-ce-cli-19.03.13-3.el8.x86_64.rpm 75 kB/s | 38 MB 08:42
Total 176 kB/s | 91 MB 08:52
warning: /var/cache/dnf/docker-ce-stable-fa9dc42ab4cec2f4/packages/containerd.io-1.3.7-3.1.el8.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Docker CE Stable - x86_64 3.5 kB/s | 1.6 kB 00:00
Importing GPG key 0x621E9F35:
Userid : "Docker Release (CE rpm) docker@docker.com"
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
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: container-selinux-2:2.124.0-1.module_el8.2.0+305+5e198a41.noarch 1/4
Installing : container-selinux-2:2.124.0-1.module_el8.2.0+305+5e198a41.noarch 1/4
Running scriptlet: container-selinux-2:2.124.0-1.module_el8.2.0+305+5e198a41.noarch 1/4
Installing : containerd.io-1.3.7-3.1.el8.x86_64 2/4
Running scriptlet: containerd.io-1.3.7-3.1.el8.x86_64 2/4
Installing : docker-ce-cli-1:19.03.13-3.el8.x86_64 3/4
Running scriptlet: docker-ce-cli-1:19.03.13-3.el8.x86_64 3/4
Installing : docker-ce-3:19.03.13-3.el8.x86_64 4/4
Running scriptlet: docker-ce-3:19.03.13-3.el8.x86_64 4/4
Running scriptlet: container-selinux-2:2.124.0-1.module_el8.2.0+305+5e198a41.noarch 4/4
Running scriptlet: docker-ce-3:19.03.13-3.el8.x86_64 4/4
Verifying : container-selinux-2:2.124.0-1.module_el8.2.0+305+5e198a41.noarch 1/4
Verifying : containerd.io-1.3.7-3.1.el8.x86_64 2/4
Verifying : docker-ce-3:19.03.13-3.el8.x86_64 3/4
Verifying : docker-ce-cli-1:19.03.13-3.el8.x86_64 4/4
Installed products updated.
Installed:
container-selinux-2:2.124.0-1.module_el8.2.0+305+5e198a41.noarch
containerd.io-1.3.7-3.1.el8.x86_64
docker-ce-3:19.03.13-3.el8.x86_64
docker-ce-cli-1:19.03.13-3.el8.x86_64
Complete!
Docker CE installation on CentOS 8

The Docker installation was completed done successfully with the message :

Installed:
container-selinux-2:2.124.0-1.module_el8.2.0+305+5e198a41.noarch
containerd.io-1.3.7-3.1.el8.x86_64
docker-ce-3:19.03.13-3.el8.x86_64
docker-ce-cli-1:19.03.13-3.el8.x86_64
Complete!

Start and Test Docker

On this stage, we will verifty the Docker installation by starting its service and querying its version. We will submit the command line : systemctl enable --now docker and systemctl status docker.

[ramans@localhsost ~]$ sudo systemctl enable --now docker
[sudo] password for ramans:
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
[ramans@localhsost ~]$ 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 Mon 2020-11-09 00:21:34 PST; 10s ago
Docs: https://docs.docker.com
Main PID: 5999 (dockerd)
Tasks: 12
Memory: 46.6M
CGroup: /system.slice/docker.service
└─5999 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Nov 09 00:21:32 localhsost dockerd[5999]: time="2020-11-09T00:21:32.382319472-08:00" level=error msg>
Nov 09 00:21:32 localhsost dockerd[5999]: time="2020-11-09T00:21:32.427647490-08:00" level=warning m>
Nov 09 00:21:32 localhsost dockerd[5999]: time="2020-11-09T00:21:32.427723798-08:00" level=warning m>
Nov 09 00:21:32 localhsost dockerd[5999]: time="2020-11-09T00:21:32.428103975-08:00" level=info msg=>
Nov 09 00:21:33 localhsost dockerd[5999]: time="2020-11-09T00:21:33.468500994-08:00" level=info msg=>
Nov 09 00:21:34 localhsost dockerd[5999]: time="2020-11-09T00:21:34.258995688-08:00" level=info msg=>
Nov 09 00:21:34 localhsost dockerd[5999]: time="2020-11-09T00:21:34.312953219-08:00" level=info msg=>
Nov 09 00:21:34 localhsost dockerd[5999]: time="2020-11-09T00:21:34.313488559-08:00" level=info msg=>
Nov 09 00:21:34 localhsost dockerd[5999]: time="2020-11-09T00:21:34.364286247-08:00" level=info msg=>
Docker services is running
Docker Service is running on CentOS 8

Docker Version

We can also query the Docker version to find out what version is running on our Centos 8, by submitting command line : docker -v.

[ramans@localhsost ~]$ docker version
Client: Docker Engine - Community
Version: 19.03.13
API version: 1.40
Go version: go1.13.15
Git commit: 4484c46d9d
Built: Wed Sep 16 17:02:36 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.13
API version: 1.40 (minimum version 1.12)
Go version: go1.13.15
Git commit: 4484c46d9d
Built: Wed Sep 16 17:01:11 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.3.7
GitCommit: 8fba4e9a7d01810a393d5d25a3621dc101981175
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
docker -v

Add user

The next step is add a user to Docker user group. On this tutorial, we will add user ramans to Docker user group.

[ramans@localhsost ~]$ sudo usermod -aG docker $USER
[sudo] password for ramans:
[ramans@localhsost ~]$ id $USER
uid=1000(ramans) gid=1000(ramans) groups=1000(ramans),10(wheel),971(docker)
[ramans@localhsost ~]$

Docker Testing

On the last step, we will deploy a simple test for our Docker installation. The testing is performed by executing the application as a “hello-world” to ensure our installation is working as expected. This step is done by submitting the command line below :

[ramans@localhsost ~]$ docker container run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:8c5aeeb6a5f3ba4883347d3747a7249f491766ca1caa47e5da5dfcf6b9b717c0
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:
The Docker client contacted the Docker daemon.
The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
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/

Install Docker Compose

For more complex Docker configurations we need tools that can help us to configure Docker. Docker has provided a tool called as Docker Compose. Compose is a tool for defining and running multi-container Docker applications. With Docker Compose, we can deploy multiple containers and an application from a single command. Docker Compose uses a YAML file to define a complex stack in a file.

Prerequisites Docker Compose Installation

  • Docker Engine running on OS (CentOS 8)
  • A non-root user

Docker Compose Installation Steps

  1. Download the current stable release of Docker Compose. When the article is written, the Docker Compose’s stabel version is version 1.27.4.
    We will use th curl command line to download the Docker Compose srouce file.
    sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  2. Apply executable permissions to the binary. We will grant access to the file as executable privilege.
    sudo chmod +x /usr/local/bin/docker-compose
  3. Test the installation. We will query the docker-compos version.
    docker-compose --version
    docker-compose version 1.27.4, build 40524192
Docker Compose installation on CentOS 8
Docker Compose installation

Conclusion

On this article we have installed the Docker Community Edition on CentOS 8 successfully. Even the CentOS 8 is not supporting the Docker, but we could install it by using Docker Repository for CentOS with --nobest option while installation. We also take a testing to install the Docker Compose tools for multi contianerDocker installation.

Share this article via :

Leave a Reply

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