Home Docker Install Docker Engine And Docker Compose In AlmaLinux, CentOS, Rocky Linux

Install Docker Engine And Docker Compose In AlmaLinux, CentOS, Rocky Linux

A Step By Step Guide To Install Docker Engine With Docker Compose In AlmaLinux, CentOS, Rocky Linux

By sk
1.8k views

The other day, we discussed what is Docker Engine and how to install Docker Engine and Docker Compose in Ubuntu. Today, we will see how to install Docker Engine with Docker Compose in RHEL-based systems such as AlmaLinux, CentOS, and Rocky Linux.

This guide has been officially tested on CentOS 8, AlmaLinux 8 and Rocky Linux 8. For demonstration purpose, I will be using AlmaLinux container which is running on Proxmox. All commands given below are same for most RHEL-based systems.

Docker Requirements

To install and configure Docker, your system must meet the following minimum requirements.

  1. 64 bit Linux or Windows operating systems.
  2. If you're on Linux, the Kernel version should be 3.10 or above.
  3. An user account with sudo privileges.
  4. VT (virtualization technology) support enabled on your system BIOS. [Read: How To Find If A CPU Supports Virtualization Technology (VT)]
  5. Your system should be connected to Internet.

In Linux, to verify the Kernel and architecture details, run the following command from the Terminal:

$ uname -a

Sample Output:

Linux Almalinux8CT 5.15.35-3-pve #1 SMP PVE 5.15.35-6 (Fri, 17 Jun 2022 13:42:35 +0200) x86_64 x86_64 x86_64 GNU/Linux

As you see in the above output, my AlmaLinux system's kernel version is 5.15.35-3-pve and my system's architecture is 64 bit (x86_64 x86_64 x86_64 GNU/Linux). Check the bold letters in the above result.

Heads Up: Here, I am using AlmaLinux 8 container in Proxmox. This is why you see the word "pve" in the kernel version in the above output. If you're using AlmaLinux physical (or virtual) machine, you will see 5.15.35-3-generic as kernel version.

Well, the Kernel version is higher than the minimum requirement, and the arch is 64 bit. So, we can install and use Docker without any problems.

Install Docker In CentOS, AlmaLinux, Rocky Linux

Make sure you are running an updated OS.

1. Update Your System

Run the following commands one by one as sudo user or root user to update your CentOS/AlmaLinux/Rocky Linux system.

$ sudo dnf --refresh update
$ sudo dnf upgrade

2. Add Docker Repository

Install the yum-utils package, which provides the yum-config-manager utility to setup repositories.

$ sudo dnf install yum-utils

Next, add Docker repository using yum-config-manger as shown below:

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

3. Install Docker

Install Docker Engine on CentOS, AlmaLinux and Rocky Linux using command:

$ sudo dnf install docker-ce docker-ce-cli containerd.io docker-compose-plugin

After Docker packages are downloaded, you will be prompted to import the Docker GPG key. Make sure that the fingerprint matches 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35, and if so, accept it.

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
Install Docker In CentOS, AlmaLinux, Rocky Linux
Install Docker In CentOS, AlmaLinux, Rocky Linux

Once Docker installation is completed, run the following commands to enable and start Docker service.

$ sudo systemctl enable docker
$ sudo systemctl start docker

Check whether Docker service is running or not with command:

$ sudo systemctl status docker

Sample Output:

● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
  Drop-In: /run/systemd/system/docker.service.d
           └─zzz-lxc-service.conf
   Active: active (running) since Tue 2022-06-28 08:17:02 UTC; 8s ago
     Docs: https://docs.docker.com
 Main PID: 2748 (dockerd)
    Tasks: 8
   Memory: 28.5M
   CGroup: /system.slice/docker.service
           └─2748 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Jun 28 08:17:02 Almalinux8CT dockerd[2748]: time="2022-06-28T08:17:02.167563866Z" level=info msg="ClientConn switching balancer to \"pick_first\""
 module=grpc
Jun 28 08:17:02 Almalinux8CT dockerd[2748]: time="2022-06-28T08:17:02.169600819Z" level=error msg="Failed to built-in GetDriver graph btrfs /var/l
ib/docker"
Jun 28 08:17:02 Almalinux8CT dockerd[2748]: time="2022-06-28T08:17:02.203579593Z" level=info msg="Loading containers: start."
Jun 28 08:17:02 Almalinux8CT dockerd[2748]: time="2022-06-28T08:17:02.350067769Z" level=info msg="Default bridge (docker0) is assigned with an IP 
address 172.17.0.0/16. Daemon option --bip can be used to set a preferred IP address"
Jun 28 08:17:02 Almalinux8CT dockerd[2748]: time="2022-06-28T08:17:02.410223534Z" level=info msg="Loading containers: done."
Jun 28 08:17:02 Almalinux8CT dockerd[2748]: time="2022-06-28T08:17:02.415653550Z" level=warning msg="Not using native diff for overlay2, this may 
cause degraded performance for building images: running in a user namespace" storage-driver=overlay2
Jun 28 08:17:02 Almalinux8CT dockerd[2748]: time="2022-06-28T08:17:02.415810806Z" level=info msg="Docker daemon" commit=a89b842 graphdriver(s)=ove
rlay2 version=20.10.17
Jun 28 08:17:02 Almalinux8CT dockerd[2748]: time="2022-06-28T08:17:02.415902359Z" level=info msg="Daemon has completed initialization"
Jun 28 08:17:02 Almalinux8CT systemd[1]: Started Docker Application Container Engine.
Jun 28 08:17:02 Almalinux8CT dockerd[2748]: time="2022-06-28T08:17:02.447662377Z" level=info msg="API listen on /var/run/docker.sock"

As you see in the above output, Docker service is up and running!

4. Check Docker Version

The installed Docker version can be found using command:

$ sudo docker version

Sample Output:

Client: Docker Engine - Community
 Version:           20.10.17
 API version:       1.41
 Go version:        go1.17.11
 Git commit:        100c701
 Built:             Mon Jun  6 23:03:11 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.17
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.17.11
  Git commit:       a89b842
  Built:            Mon Jun  6 23:01:29 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.6
  GitCommit:        10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc:
  Version:          1.1.2
  GitCommit:        v1.1.2-0-ga916309
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
Check Docker Version In AlmaLinux
Check Docker Version In AlmaLinux

5. Testing Docker

Let us go ahead, and test whether Docker is working or not. We can run a hello-world docker image to verify if Docker is properly installed and working.

To do so, run:

$ sudo docker run hello-world

The above command will download a test Docker image, and execute a sample hello_world program inside the container.

If you see an output something like below, congratulations! Docker is working fine in your CentOS/AlmaLinux/Rocky Linux system.

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:13e367d31ae85359f42d637adf6da428f76d75dc9afeb3c21faea0d976f5c651
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/
Run Hello World Docker Container In AlmaLinux
Run Hello World Docker Container In AlmaLinux

Docker is ready to use!

I installed Docker, now what? Check the next article in this series to learn the Docker basics.

6. Upgrade Docker

Since we've installed Docker using the repository, we can upgrade Docker engine to latest available version by simply running the following commands:

$ sudo dnf --refresh update
$ sudo dnf upgrade

Install Docker Compose

Docker Compose is a tool that can be used to define and run multi-container Docker applications. With Compose, you use a Compose file to configure your application’s services. Then, using a single command, you can create and start all the services from your configuration.

We can install Docker Compose using any one of the following methods.

Method 1 - Install Docker Compose Using Binary

Download the latest Docker Compose from here.

As of writing this, the latest version was 2.6.1.

Run the following command to download latest stable Docker compose file:

$ sudo curl -L "https://github.com/docker/compose/releases/download/v2.6.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

If a new version is available, just replace the number v2.6.1 in the above command with the new version number. Please don't forget to preface "v" before the version number.

Finally, apply executable permissions to the binary using command:

$ sudo chmod +x /usr/local/bin/docker-compose

To check installed docker composer version, run:

$ docker-compose version
Docker Compose version v2.6.1

Method 2 - Install Docker Compose Using PiP

Alternatively, we can install Docker Compose using PIP. Pip is a python package manager used to install applications written in Python programming language.

Refer the following guide to install Pip on your system.

Once pip installed, run the following command to install docker compose. The following command is same for all Linux distributions!

$ pip install docker-compose

After installing Docker Compose, you can check the version with command:

$ docker-compose --version

You will see an output something like below.

docker-compose version 2.6.1, build 8a1c60f6

Congratulations! We have successfully installed Docker Community Edition and Docker Compose.

Read our introductory guide to Docker Compose to learn how to use Docker compose in real time to define and manage containers.

Upgrade Docker Compose

To upgrade Docker Compose, simply download the newer package file and repeat the installation instructions as shown in Method 1. If you have installed Compose using Pip, you can upgrade Docker Compose using the following command:

$ pip install --upgrade docker-compose

Uninstall Docker Engine

To remove Docker Engine from your CentOS, AlmaLinux and Rock Linux system, run:

$ sudo dnf remove docker-ce docker-ce-cli containerd.io docker-compose-plugin

The Docker images, containers, volumes, or customized configuration files on your system are not automatically removed.

You should manually delete all images, containers, and volumes using the following commands:

$ sudo rm -rf /var/lib/docker
$ sudo rm -rf /var/lib/containerd

Uninstall Docker Compose

If you have installed Compose using binary file, simply remove it from /usr/local/bin/ path.

$ sudo rm /usr/local/bin/docker-compose

If you installed Compose using PiP, run the following command to remove Docker Compose:

$ pip uninstall docker-compose

Conclusion

We know how to install Docker Engine and Docker Compose in CentOS, AlmaLinux and Rocky Linux. We also learned how to test Docker engine by running a basic hello-world docker image. Finally, we saw how to remove Docker engine and docker compose when they are no longer required.

Resource:

You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

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

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More