Install Docker CE & Docker Compose on CentOS 8 | RHEL 8

Posted on 142 views

In this guide we’ll be walking you through the steps of installing Docker CE on CentOS 8 | RHEL 8. We’ll also cover how to install Docker Compose on RHEL 8 / CentOS 8 Linux?. Docker is not officially supported on RHEL 8 as it has been replaced with Red Hat tools – buildah and podman.

But what if you use Docker every single day and can’t switch to buildah and podman immediately?, don’t worry since there is a way to install Docker and Docker Compose on RHEL 8 / CentOS 8. Docker is a tool that enables you to create, deploy and run your applications in containers. Containers allow a Developer to package an application with its dependencies and ship it out as a single package. Containers are often used in Microservices environments.

Docker Components / Terminologies

There is a number of Docker specific jargon that we need to clarify before diving into installation and usage examples. Below are commonly used terminologies in Docker ecosystem.

  • Docker daemon: This is also called Docker Engine, it is a background process which runs on the host system responsible for building and running of containers.
  • Docker Client: This is a command line tool used by the user to interact with the Docker daemon.
  • Docker Image: An image is an immutable file that’s essentially a snapshot of a container. A docker image has a file system and application dependencies required for running applications.
  • Docker container: This is a running instance of a docker image with an application and its dependencies. Each container has a unique process ID and isolated from other containers. The only thing containers share is the Kernel.
  • Docker registry: This is an application responsible for managing storage and delivery of Docker container images. It can be private or public.

Install Docker CE on CentOS 8 | RHEL 8

So far we have covered docker introduction and terminologies. We should be ready to install Docker CE on RHEL 8 / CentOS 8. We will start with the installation of Docker then Docker Compose.

There are two editions of Docker available.

  • Community Edition (CE): ideal for individual developers and small teams looking to get started with Docker and experimenting with container-based apps.
  • Enterprise Edition (EE): Designed for enterprise development and IT teams who build, ship, and run business-critical applications in production at scale.

The Docker Enterprise Edition requires an active license to use. In this guide, we will install Docker CE on RHEL 8. Let’s add Docker repository before we can install it.

### CentOS 8 ###
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

### RHEL 8 ###
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo

This command will download Docker repository file to /etc/yum.repos.d/docker-ce.repo. Let’s update RPM index cache.

### CentOS 8 ###
$ sudo yum makecache 
CentOS Linux 8 - AppStream                                                                                                                                             23 kB/s | 4.3 kB     00:00
CentOS Linux 8 - BaseOS                                                                                                                                                20 kB/s | 3.9 kB     00:00
CentOS Linux 8 - Extras                                                                                                                                               9.2 kB/s | 1.5 kB     00:00
Docker CE Stable - x86_64                                                                                                                                             291 kB/s |  19 kB     00:00
DigitalOcean Droplet Agent                                                                                                                                             51 kB/s | 3.3 kB     00:00
Metadata cache created.

### RHEL 8 ###
$ sudo yum makecache 
Updating Subscription Management repositories.
Docker CE Stable - x86_64                                                                                                                                             14 kB/s | 3.8 kB     00:00    
Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs)                                                                                                              33 kB/s | 2.8 kB     00:00    
Red Hat Ansible Engine 2.8 for RHEL 8 x86_64 (RPMs)                                                                                                                   29 kB/s | 2.4 kB     00:00    
Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)                                                                                                                 30 kB/s | 2.4 kB     00:00    
Red Hat Satellite Tools 6.6 for RHEL 8 x86_64 (RPMs)                                                                                                                  29 kB/s | 2.1 kB     00:00    
Metadata cache created.

You may need to uninstall all older versions of Docker along with associated dependencies. Also uninstall Podman and the associated dependencies if installed already.

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

Finally install Docker CE by running the command below in your terminal.

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

If you get dependency issues with Podman allow errasing.

sudo yum install docker-ce --allowerasing

Agree to install by hitting the key in your keyboard:

Dependencies resolved.
================================================================================================================================================================================================
 Package                                          Architecture                  Version                                                           Repository                               Size
================================================================================================================================================================================================
Installing:
 containerd.io                                    x86_64                        1.6.4-3.1.el8                                                     docker-ce-stable                         33 M
 docker-ce                                        x86_64                        3:20.10.15-3.el8                                                  docker-ce-stable                         21 M
 docker-ce-cli                                    x86_64                        1:20.10.15-3.el8                                                  docker-ce-stable                         29 M
Installing dependencies:
 container-selinux                                noarch                        2:2.173.0-1.module+el8.5.0+735+2f243138                           appstream                                56 k
 docker-ce-rootless-extras                        x86_64                        20.10.15-3.el8                                                    docker-ce-stable                        4.7 M
 docker-scan-plugin                               x86_64                        0.17.0-3.el8                                                      docker-ce-stable                        3.8 M
 fuse-overlayfs                                   x86_64                        1.8-1.module+el8.5.0+735+2f243138                                 appstream                                72 k
 fuse3                                            x86_64                        3.2.1-12.el8                                                      baseos                                   49 k
 fuse3-libs                                       x86_64                        3.2.1-12.el8                                                      baseos                                   93 k
 libcgroup                                        x86_64                        0.41-19.el8                                                       baseos                                   69 k
 libslirp                                         x86_64                        4.4.0-1.module+el8.5.0+710+4c471e88                               appstream                                69 k
 slirp4netns                                      x86_64                        1.1.8-1.module+el8.5.0+710+4c471e88                               appstream                                50 k

Transaction Summary
================================================================================================================================================================================================
Install  12 Packages

Total download size: 93 M
Installed size: 389 M
Is this ok [y/N]: y

Import GPG key as well.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                            51 MB/s |  93 MB     00:01
Docker CE Stable - x86_64                                                                                                                                        44 kB/s | 1.6 kB     00:00
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

Start and enable Docker Service to start at boot.

$ sudo systemctl enable --now docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.

The docker service status should indicate running.

$ 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 Tue 2020-10-06 17:05:53 EAT; 2min 32s ago
     Docs: https://docs.docker.com
 Main PID: 230185 (dockerd)
    Tasks: 13
   Memory: 41.4M
   CGroup: /system.slice/docker.service
           └─230185 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
....

The docker group is created, but no users are added to the group. Add your user to this group to run docker commands without sudo

$ sudo usermod -aG docker $USER
$ newgrp docker
$ id $USER
uid=1000(jmutai) gid=1000(jmutai) groups=1000(jmutai),10(wheel),984(docker)

Logout and Login again to use Docker without sudo. The version of Docker installed can be checked with:

$ docker version
Client: Docker Engine - Community
 Version:           20.10.15
 API version:       1.41
 Go version:        go1.17.9
 Git commit:        fd82621
 Built:             Thu May  5 13:15:49 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.15
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.17.9
  Git commit:       4433bf6
  Built:            Thu May  5 13:14:10 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.4
  GitCommit:        212e8b6fa2f44b9c21b2798135fc6fb7c53efc16
 runc:
  Version:          1.1.1
  GitCommit:        v1.1.1-0-g52de29d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Pull Test docker image

The last step is to test your installation by downloading a test docker container.

$ docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
8e402f1a9c57: Pull complete 
Digest: sha256:644fcb1a676b5165371437feaa922943aaf7afcfa8bfee4472f6860aad1ef2a0
Status: Downloaded newer image for alpine:latest

$ docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:cc15c5b292d8525effc0f89cb299f1804f3a725c8d05e158653a563f15e4f685
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest

List downloaded images.

$ docker images
 REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
 alpine              latest              5cb3aa00f899        2 days ago          5.53MB
 hello-world         latest              fce289e99eb9        2 months ago        1.84kB

Verify that Docker CE is working correctly by running the alpine container from downloaded image.

$ docker run -it --rm alpine /bin/sh
/ # apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
v3.15.4-87-g89e29fdace [http://dl-cdn.alpinelinux.org/alpine/v3.15/main]
v3.15.4-87-g89e29fdace [http://dl-cdn.alpinelinux.org/alpine/v3.15/community]
OK: 9754 distinct packages available
/ # exit

Hello world container run

$ docker run -it --rm hello-world

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/

Install Docker Compose on CentOS 8 | CentOS 8

We have Docker installed and running, let’s now change gear to Docker Compose. Docker Compose is a tool used to define and run multi-container Docker applications.

The application services are configured using a Compose file. Unlike running docker commands, a single command is all that’s required to create and start all the services from your configuration. Docker Compose is a great tool for development, testing, and staging environments, as well as CI workflows.

Follow our separate guide on installation of latest Docker Compose on Linux.

For the sake of keeping this guide brief, we won’t dive into Docker compose usage. I’ll recommend you go through Official Docker documentation and Docker Compose documentation to learn more.

Install Docker UI – Optional

If you need Docker management UI which allows you to easily manage your different Docker hosts and containers, please give Portainer a try. It is easy to install and use.

Monitoring Docker containers

Monitoring Docker containers can be achieved by using Monitoring tools such as Netdata or Ctop or Prometheus and Grafana. Below guides should be helpful.

Ctop – Top command for container metrics

How to Install Netdata on RHEL 8 / CentOS 8

Install Harbor Docker registry on Linux

coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.