Installing Docker on RHEL/ CentOS 8

Docker is a tool that uses kernel modules like namespace and cgroups to run container over single OS Instance.

It provides lightweight and efficient environment to deploy and manage applications by creating containers.

We are going to see Installing docker on RHEL/ CentOS 8 in this post

Installing Docker on RHEL/ CentOS 8

Docker available in below two types:

Docker EE(Enterprise Edition)
Docker CE(Community Edition)

Pre-Requisites:

Uninstall the old version of Docker using below command

yum  -y remove  docker-common docker container-selinux docker-selinux docker-engine

Your existing containers will be remain under /var/lib/docker

Installing dependent packages:
# yum -y install lvm2 device-mapper device-mapper-persis                                                                                        tent-data device-mapper-event device-mapper-libs device-mapper-event-libs
Adding Docker Repository:

Docker Inc still didnt replease Docker for RHEL8/ CentOS 8. So, we can use alternate one which is used for RHEL7/ CentOS7

# curl https://download.docker.com/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2424 100 2424 0 0 22238 0 --:--:-- --:--:-- --:--:-- 22238

Docker community edition requires container.io => 1.2.2.3. But, its not available for RHEL/ CentOS 8. So, we need to skip and proceed the the docker installation in our own RISK.

# yum install docker-ce
Docker CE Stable - x86_64 16 kB/s | 21 kB 00:01
Error:
Problem: package docker-ce-3:19.03.5-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed

cannot install the best candidate for the job
package containerd.io-1.2.10-3.2.el7.x86_64 is excluded
package containerd.io-1.2.2-3.3.el7.x86_64 is excluded
package containerd.io-1.2.2-3.el7.x86_64 is excluded
package containerd.io-1.2.4-3.1.el7.x86_64 is excluded
package containerd.io-1.2.5-3.1.el7.x86_64 is excluded
package containerd.io-1.2.6-3.3.el7.x86_64 is excluded
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
Installing docker by skipping unavailable packages
[root@ip-172-31-44-32 ~]# yum -y install docker-ce --nobest
Output:
Installed:
docker-ce-3:18.09.1-3.el7.x86_64 containerd.io-1.2.0-3.el7.x86_64 docker-ce-cli-1:19.03.5-3.el7.x86_64
container-selinux-2:2.94-1.git1e99f1d.module+el8.0.0+4017+bbba319f.noarch libnftnl-1.1.1-4.el8.x86_64 libcgroup-0.41-19.el8.x86_64
policycoreutils-python-utils-2.8-16.1.el8.noarch libnfnetlink-1.0.1-13.el8.x86_64 libnetfilter_conntrack-1.0.6-5.el8.x86_64
iptables-1.8.2-9.el8_0.1.x86_64


Skipped:
docker-ce-3:19.03.5-3.el7.x86_64


Complete!

Now Docker Version “3:18.09.1-3.el7.x86_64” has been installed.S

Start and enable the Docker service by using below command
# systemctl start docker

# systemctl enable docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service â /usr/lib/systemd/system/docker.service.
Check the docker service status
# 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 Fri 2020-01-17 05:37:17 UTC; 2min 4s ago
Docs: https://docs.docker.com
Main PID: 15635 (dockerd)
Tasks: 18
Memory: 53.5M
CGroup: /system.slice/docker.service
ââ15635 /usr/bin/dockerd -H fd://
ââ15649 containerd --config /var/run/docker/containerd/containerd.toml --log-level info
Jan 17 05:37:17 ip-172-31-44-32.us-east-2.compute.internal dockerd[15635]: time="2020-01-17T05:37:17.341886251Z" level=info msg="Graph migration to content-addressabil>
Jan 17 05:37:17 ip-172-31-44-32.us-east-2.compute.internal dockerd[15635]: time="2020-01-17T05:37:17.342289173Z" level=warning msg="Your kernel does not support cgroup>
Jan 17 05:37:17 ip-172-31-44-32.us-east-2.compute.internal dockerd[15635]: time="2020-01-17T05:37:17.342309354Z" level=warning msg="Your kernel does not support cgroup>
Jan 17 05:37:17 ip-172-31-44-32.us-east-2.compute.internal dockerd[15635]: time="2020-01-17T05:37:17.342708097Z" level=info msg="Loading containers: start."
Jan 17 05:37:17 ip-172-31-44-32.us-east-2.compute.internal dockerd[15635]: time="2020-01-17T05:37:17.556082824Z" level=info msg="Default bridge (docker0) is assigned w>
Jan 17 05:37:17 ip-172-31-44-32.us-east-2.compute.internal dockerd[15635]: time="2020-01-17T05:37:17.654816733Z" level=info msg="Loading containers: done."
Jan 17 05:37:17 ip-172-31-44-32.us-east-2.compute.internal dockerd[15635]: time="2020-01-17T05:37:17.681089736Z" level=info msg="Docker daemon" commit=4c52b90 graphdri>
Jan 17 05:37:17 ip-172-31-44-32.us-east-2.compute.internal dockerd[15635]: time="2020-01-17T05:37:17.681241065Z" level=info msg="Daemon has completed initialization"
Jan 17 05:37:17 ip-172-31-44-32.us-east-2.compute.internal dockerd[15635]: time="2020-01-17T05:37:17.717122644Z" level=info msg="API listen on /var/run/docker.sock"
Jan 17 05:37:17 ip-172-31-44-32.us-east-2.compute.internal systemd[1]: Started Docker Application Container Engine.

Now check the Docker installation by running a container using anyone the base image

# docker run -it hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:9572f7cdcee8591948c2963463447a53466950b3fc15a247fcad1917ca215a2f
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/

Allowing non root users:

Check whether group called “Docker” availavle or not

# cat /etc/group | grep docker
docker:x:989:

Since group already exists, Now create a new user

# useradd abu

Check created users details like default UID, GID/ Groups added

# id abu
uid=1001(abu) gid=1001(abu) groups=1001(abu)

Now add “abu” user to “Docker” group as another group.

# usermod -aG docker abu

# id abu
uid=1001(abu) gid=1001(abu) groups=1001(abu),989(docker)

Now we can use this user to run docker instead if using root user.

Leave a Reply

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