HomeCONTAINERSInstall Docker CE on Rocky Linux 9|AlmaLinux 9

Install Docker CE on Rocky Linux 9|AlmaLinux 9

Follow along as we demonstrate how to Install Docker CE on Rocky Linux 9|AlmaLinux 9.

Docker is a widely used containerization platform tool that enables users to develop, test, and deploy applications inside containers in a streamlined and efficient manner.
A container is a small, portable unit that runs entirely independently of the underlying operating system.
It includes the source code of the application, as well as its libraries, dependencies, and configuration.

Containers enable developers to deploy applications consistently across multiple environments with the same consistency, which is one of the reasons why modern developers cannot ignore Docker and other containerization platforms.

Docker is available in two editions:

  • Docker community edition (Docker CE)
  • Docker enterprise edition (Docker EE) (Docker EE).

The community edition is free and open source, whereas the enterprise edition is a paid version.

Install Docker CE on Rocky Linux 9|AlmaLinux 9

The following steps will take you through the installation of Docker CE on Rocky Linux 9|AlmaLinux 9.

Step 1: Add Docker repository to Rocky Linux 9|AlmaLinux 9

Docker is currently not available in the default repositories. Fortunately, developers have provided an official repository, which we will add to the system first.

Run the following command in your terminal to add the Docker repository.

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

Step 2: Install Docker in Rocky Linux 9|AlmaLinux 9

Next, we’ll install the Docker community edition, which is a free version.
But first, make sure the packages are up to date.

sudo dnf update

Next, run the command below to install Docker CE, the command-line interface (CLI), and other essential tools and dependencies.

sudo dnf install -y docker-ce docker-ce-cli containerd.io

Note: If you got an error pass the above command with –allowerasing.

sudo dnf install -y docker-ce docker-ce-cli containerd.io --allowerasing

Dependency tree;

Dependencies resolved.
============================================================================================================================
 Package                               Architecture       Version                        Repository                    Size
============================================================================================================================
Installing:
 containerd.io                         x86_64             1.6.10-3.1.el9                 docker-ce-stable              32 M
     replacing  runc.x86_64 4:1.1.3-2.el9_0
 docker-ce                             x86_64             3:20.10.21-3.el9               docker-ce-stable              21 M
 docker-ce-cli                         x86_64             1:20.10.21-3.el9               docker-ce-stable              29 M
Installing dependencies:
 docker-ce-rootless-extras             x86_64             20.10.21-3.el9                 docker-ce-stable             3.7 M
Installing weak dependencies:
 docker-scan-plugin                    x86_64             0.21.0-3.el9                   docker-ce-stable             3.8 M
Removing dependent packages:
 buildah                               x86_64             1:1.26.2-1.el9_0               @appstream                    29 M

Transaction Summary
........

Verify that you have installed the correct version of Docker after installation.
The result reveals that Docker 20.10 has been set up.

$ docker --version                                                                                   
Docker version 23.0.1, build a5ee5b1

Step 3: Start and Enable Docker

We must launch the Docker daemon before we can use Docker. But first, let’s make it such that it starts when the computer boots, as indicated.

sudo systemctl enable docker
sudo systemctl start docker
sudo systemctl status docker

The output of the sudo 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 Wed 2023-03-15 22:50:10 EAT; 6s ago                                                 TriggeredBy: ● docker.socket                                                                                                   Docs: https://docs.docker.com                                                                                       Main PID: 5846 (dockerd)                                                                                                   Tasks: 8                                                                                                               Memory: 100.6M                                                                                                             CPU: 268ms                                                                                                           CGroup: /system.slice/docker.service                                                                                            └─5846 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock    

Perfect! The operation of Docker is normal.

Step 4: Add User to Docker Group

You must add the user to the Docker group in order to execute Docker commands without the sudo command.

sudo usermod -aG docker $USER
newgrp docker

Verify using the command below;

$ id $USER
uid=1000(ezrah) gid=1000(ezrah) groups=1000(ezrah),10(wheel),975(docker)

Now, you may run the docker command without requiring sudo.

Docker version information.

$ docker version                                                                                                                                                                                                          Client: Docker Engine - Community                                                                                                                                                                                                             Version:           23.0.1                                                                                                                                                                                                                    API version:       1.42                                                                                                                                                                                                                      Go version:        go1.19.5                                                                                                                                                                                                                  Git commit:        a5ee5b1                                                                                                                                                                                                                   Built:             Thu Feb  9 19:49:35 2023                                                                                                                                                                                                  OS/Arch:           linux/amd64                                                                                                                                                                                                               Context:           default                                                                                                                                                                                                                                                                                                                                                                                                                                                               Server: Docker Engine - Community                                                                                                                                                                                                             Engine:                                                                                                                                                                                                                                       Version:          23.0.1                                                                                                                                                                                                                     API version:      1.42 (minimum version 1.12)                                                                                                                                                                                                Go version:       go1.19.5                                                                                                                                                                                                                   Git commit:       bc3805a                                                                                                                                                                                                                    Built:            Thu Feb  9 19:46:32 2023                                                                                                                                                                                                   OS/Arch:          linux/amd64                                                                                                                                                                                                                Experimental:     false                                                                                                                                                                                                                     containerd:                                                                                                                                                                                                                                   Version:          1.6.18                                                                                                                                                                                                                     GitCommit:        2456e983eb9e37e47538f59ea18f2043c9a73640                                                                                                                                                                                  runc:                                                                                                                                                                                                                                         Version:          1.1.4                                                                                                                                                                                                                      GitCommit:        v1.1.4-0-g5fd4c4d                                                                                                                                                                                                         docker-init:                                                                                                                                                                                                                                  Version:          0.19.0                                                                                                                                                                                                                     GitCommit:        de40ad0 

Step 5: Testing Docker in Rocky Linux 9|AlmaLinux 9

Run the hello-world container as specified in the command below to check Docker is functioning as expected.

docker run hello-world

The command merely downloads the hello-world image from the repository for Docker container images known as the Docker hub.
The container that prints the “Hello from Docker” message on the console is then created and executed.
This is unequivocal evidence that Docker was set up effectively.

Output;

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:faa03e786c97f07ef34423fccceeec2398ec8a5759259f94d99078f264e9d7af
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/

Let’s venture further. We’ll obtain an Ubuntu image, launch it, and communicate with the container.

Step 6: Pull Ubuntu Docker Image

Run the following command to retrieve the most recent Ubuntu image.

$ docker pull ubuntu

Using default tag: latest
latest: Pulling from library/ubuntu
e96e057aae67: Pull complete 
Digest: sha256:4b1d0c4a2d2aaf63b37111f34eb9fa89fa1bf53dd6e4ca954d47caebca4005c2
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest

Verify the current photos are as shown once the image has been pulled.

$ docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
ubuntu        latest    a8780b506fa4   2 weeks ago     77.8MB
hello-world   latest    feb5d9fea6a5   14 months ago   13.3kB

Step 7: Run Ubuntu Docker Container

Run the command below to get to the Ubuntu container’s shell.

$ docker run -it ubuntu

root@9cacd97341a7:/# cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

From this point, you can operate commands, manage packages, and handle other system duties inside the container. When finished, click “exit” to leave the container and return to your OS environment.

Conclusion

That concludes this guide. We’ve shown how to set up Docker on Rocky Linux 9 and AlmaLinux 9 and start downloading images and running containers. Cheers!

More info about Docker.

Other cool guides:

- Advertisment -

Recent posts

LEAVE A REPLY

Please enter your comment!
Please enter your name here