Docker on Rocky Linux

Published On: January 4, 2023

Docker on Rocky Linux

This article will help you to install Docker on Rocky Linux or CentOS Linux.

Pre-requisites

A Linux system running Rocky Linux 9 with internet access.

Please follow below steps from the root console

Since Rocky Linux won’t allow root login via SSH, we need a non-root user to install docker via SSH terminal.

  • Create an admin user
useradd acloudlabs
  • Set password for admin user
passwd acloudlabs
  • Add admin user to “wheel” group
usermod -aG wheel acloudlabs

# Step 1

  • Logon to the system via SSH so that you can easily copy and paste the commands to the terminal.
  • Install dnf-plugin-core if not already installed.
sudo dnf -y install dnf-plugins-core
[acloudlabs@localhost ~]$ sudo dnf -y install dnf-plugins-core
Last metadata expiration check: 0:00:28 ago on Thu 16 Mar 2023 12:58:51 AM IST.
Package dnf-plugins-core-4.1.0-3.el9.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[acloudlabs@localhost ~]$ 

# Step 2

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

# Step 3

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

Output will end with below;


...
...
Installed:
  containerd.io-1.6.18-3.1.el9.x86_64                          docker-buildx-plugin-0.10.2-1.el9.x86_64
  docker-ce-3:23.0.1-1.el9.x86_64                              docker-ce-cli-1:23.0.1-1.el9.x86_64
  docker-ce-rootless-extras-23.0.1-1.el9.x86_64                docker-compose-plugin-2.16.0-1.el9.x86_64
  docker-scan-plugin-0.23.0-3.el9.x86_64

Complete!

# Step 4

  • Start the docker service
sudo systemctl start docker.service
  • Check the state of the docker service
sudo systemctl status docker.service

Output:-

● docker.service - Docker Application Container Engine
     Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
     Active: active (running) since Thu 2023-03-16 02:52:33 IST; 5s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 29086 (dockerd)
      Tasks: 10
     Memory: 28.8M
        CPU: 91ms
     CGroup: /system.slice/docker.service
             └─29086 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Mar 16 02:52:33 localhost.localdomain dockerd[29086]: time="2023-03-16T02:52:33.314978705+05:30" level=info msg="[core] [Channel #4] Channel Connectivity change to READY" module=grpc
Mar 16 02:52:33 localhost.localdomain dockerd[29086]: time="2023-03-16T02:52:33.321608005+05:30" level=info msg="Loading containers: start."
Mar 16 02:52:33 localhost.localdomain dockerd[29086]: time="2023-03-16T02:52:33.607902994+05:30" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can>
Mar 16 02:52:33 localhost.localdomain dockerd[29086]: time="2023-03-16T02:52:33.668447286+05:30" level=info msg="Firewalld: interface docker0 already part of docker zone, returning"
Mar 16 02:52:33 localhost.localdomain dockerd[29086]: time="2023-03-16T02:52:33.723955034+05:30" level=info msg="Loading containers: done."
Mar 16 02:52:33 localhost.localdomain dockerd[29086]: time="2023-03-16T02:52:33.732200741+05:30" level=info msg="Docker daemon" commit=bc3805a graphdriver=overlay2 version=23.0.1
Mar 16 02:52:33 localhost.localdomain dockerd[29086]: time="2023-03-16T02:52:33.732433863+05:30" level=info msg="Daemon has completed initialization"
Mar 16 02:52:33 localhost.localdomain dockerd[29086]: time="2023-03-16T02:52:33.744604615+05:30" level=info msg="[core] [Server #7] Server created" module=grpc
Mar 16 02:52:33 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
Mar 16 02:52:33 localhost.localdomain dockerd[29086]: time="2023-03-16T02:52:33.748577037+05:30" level=info msg="API listen on /run/docker.sock"

# Step 5

  • Add the admin user to the docker group
sudo usermod -aG docker acloudlabs
[acloudlabs@localhost ~]$ id acloudlabs
uid=1000(acloudlabs) gid=1000(acloudlabs) groups=1000(acloudlabs),10(wheel),984(docker)
[acloudlabs@localhost ~]$

Make sure to exit the terminal and login again to get the docker group permission.

  • verify the docker engine state using below command.
docker run hello-world

Output:-

[acloudlabs@localhost ~]$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:63421b18c1443a9a85139225293fae7541fb40b7832d9deff80b6a9a75ce3604
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/

[acloudlabs@localhost ~]$

Conclusion

Congratulations.!!!

Now you are familiar with the steps to install and verify Docker engine on Rocky Linux 9. In the next session, we will build a container from scratch and will also discuss the lifecycle of containers.


About the Author

Ansil

Ansil Hameed Kunju

Ansil has more than a decade of experience in different IT domains. He is an expert in DevOps.His skill set includes Linux, GCP, AWS, VMware, Nutanix, Rancher, Docker, Git, Python, Golang, Kubernetes, Istio, Prometheus, Grafana, ArgoCD, Jenkins, StackStorm and other CNCF projects.