Site icon CentLinux

How to install Docker on Rocky Linux 9

Share on Social Media

Discover how to seamlessly install Docker on Rocky Linux 9 with our step-by-step guide. Dive into the world of containerization and streamline your application deployment process with this comprehensive tutorial tailored for efficient integration on your Linux environment. #centlinux #linux #docker

What is Docker?:

Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers. The service has both free and premium tiers. The software that hosts the containers is called Docker Engine. It was first started in 2013 and is developed by Docker, Inc. (Source: Wikipedia)

Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels. Because all of the containers share the services of a single operating system kernel, they use fewer resources than virtual machines.

Docker can package an application and its dependencies in a virtual container that can run on any Linux, Windows, or macOS computer. This enables the application to run in a variety of locations, such as on-premises, in public (see decentralized computing, distributed computing, and cloud computing) or private cloud. When running on Linux, Docker uses the resource isolation features of the Linux kernel (such as cgroups and kernel namespaces) and a union-capable file system (such as OverlayFS) to allow containers to run within a single Linux instance, avoiding the overhead of starting and maintaining virtual machines. Docker on macOS uses a Linux virtual machine to run the containers.

What is a Docker Container?

A Docker container is a lightweight, standalone, and executable package that contains everything needed to run a piece of software, including code, runtime, system tools, system libraries, and settings. Containers are isolated environments that run on top of a host operating system’s kernel and share the host OS’s resources, such as CPU, memory, and storage.

Here are some key characteristics of Docker containers:

  1. Isolation: Containers provide process isolation, allowing multiple containers to run on the same host without interfering with each other. Each container has its own filesystem, network stack, and process space, ensuring that applications and their dependencies are isolated from one another.
  2. Portability: Docker containers are highly portable and can be deployed across different environments, including development, testing, staging, and production, with minimal changes. Containers encapsulate all dependencies and configurations, making them easy to move between environments without worrying about compatibility issues.
  3. Efficiency: Containers are lightweight and efficient, consuming fewer resources compared to traditional virtual machines (VMs). Containers share the host OS’s kernel and only contain the necessary components to run a specific application, resulting in faster startup times and reduced overhead.
  4. Reproducibility: Docker containers provide a consistent and reproducible environment for running applications. Developers can package their applications and dependencies into containers, ensuring that the environment remains consistent across different deployments and environments.
  5. Scalability: Docker containers are highly scalable and can be easily scaled up or down to meet changing workload demands. Containers can be orchestrated and managed using container orchestration platforms like Docker Swarm or Kubernetes, allowing for automated deployment, scaling, and management of containerized applications.

Overall, Docker containers provide a convenient and efficient way to package, distribute, and run software applications, offering benefits such as isolation, portability, efficiency, reproducibility, and scalability. They have become a popular choice for modern application development and deployment, enabling developers to build and deploy applications faster and more reliably across diverse environments.

What is a Docker Image?

A Docker image is a lightweight, standalone, and executable package that contains everything needed to run a Docker container. It serves as a template for creating Docker containers, encapsulating all the necessary dependencies, configurations, and files required to run a specific application or service.

Here are some key characteristics of Docker images:

  1. Immutable: Docker images are immutable, meaning they are read-only and cannot be modified once created. Any changes to the image result in the creation of a new image layer, preserving the integrity of the original image.
  2. Layered Filesystem: Docker images are built using a layered filesystem, where each layer represents a set of changes to the filesystem. Layers are stacked on top of each other to form the complete image. This allows for efficient storage and sharing of image layers, as well as faster image building and deployment.
  3. Reusability: Docker images are designed for reusability, allowing developers to create and share standardized images for common software components or services. Images can be stored in public or private registries, such as Docker Hub or a private registry, and reused across different projects and environments.
  4. Versioning: Docker images can be versioned using tags, allowing developers to track different versions of an image. Tags typically represent different versions of the software or configurations contained within the image, making it easy to reference and deploy specific versions of an image.
  5. Layer Cache: Docker images leverage layer caching during the build process, which speeds up subsequent builds by reusing previously built layers. This helps reduce build times and improves developer productivity.

Overall, Docker images serve as the building blocks for creating Docker containers, providing a standardized and portable way to package and distribute software applications and services. They enable developers to build, share, and deploy applications more efficiently and reliably in containerized environments.

Recommended Online Training: Docker for absolute beginners

Environment Specification

We are using a minimal Rocky Linux 9 virtual machine with following specifications.

Prepare your Docker Host:

By using a ssh client, login to your Rocky Linux server as root user.

Set a FQDN (Fully Qualified Domain Name) hostname for your Docker Host machine.

# hostnamectl set-hostname docker-01.centlinux.com

Refresh your cache for enabled yum repositories.

# dnf makecache --refresh
Rocky Linux 9 - BaseOS                          302 kB/s | 1.7 MB     00:05
Rocky Linux 9 - AppStream                       638 kB/s | 6.0 MB     00:09
Rocky Linux 9 - Extras                          961  B/s | 2.9 kB     00:03
Metadata cache created.

Execute following dnf command to update software packages in your Docker Server.

# dnf update -y

The above may updates the software packages related to Linux Kernel. In such case, you should reboot your Linux operating system with latest Linux Kernel before installing Docker CE software.

# reboot

After reboot, Check the versions of Linux Kernel and Operating System.

# cat /etc/rocky-release
Rocky Linux release 9.0 (Blue Onyx)

# uname -r
5.14.0-70.30.1.el9_0.x86_64

Install Docker Yum Repository:

Community’s most favorite containerization software is available via Docker’s Official Yum Repository.

Execute following command to download and install Docker Yum repository on your Rocky Linux server.

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

You have added a new yum repository, therefore, rebuild your yum cache again.

# dnf makecache
Docker CE Stable - x86_64                       5.6 kB/s |  12 kB     00:02
Rocky Linux 9 - BaseOS                          1.6 kB/s | 3.6 kB     00:02
Rocky Linux 9 - AppStream                       1.4 kB/s | 3.6 kB     00:02
Rocky Linux 9 - Extras                          845  B/s | 2.9 kB     00:03
Metadata cache created.

How to install Docker on Rocky Linux 9

You have added Docker yum repository in your Linux server. Now you can easily install Docker on Linux by using dnf command.

# dnf install -y docker-ce

Enable and start Docker service.

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

Check the status of Docker service for any errors.

# systemctl status docker.service
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor pr>
Active: active (running) since Sun 2022-11-06 04:00:18 CST; 11s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 2728 (dockerd)
Tasks: 9
Memory: 28.3M
CPU: 450ms
CGroup: /system.slice/docker.service
└─2728 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/cont>

Nov 06 04:00:18 docker-01.centlinux.com dockerd[2728]: time="2022-11-06T04:00:1>
Nov 06 04:00:18 docker-01.centlinux.com systemd[1]: Started Docker Application >

Verify that the Docker command is working fine by querying the version of you Containerization software.

# docker version
Client: Docker Engine - Community
 Version:           20.10.21
 API version:       1.41
 Go version:        go1.18.7
 Git commit:        baeda1f
 Built:             Tue Oct 25 18:02:16 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.21
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.7
  Git commit:       3056208
  Built:            Tue Oct 25 18:00:01 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.9
  GitCommit:        1c90a442489720eec95342e1789ee8a5e1b9536f
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Examples of Docker Command Usage:

Search Docker Hub for Alpine Linux images, you can use the –filter switch to list only Official images.

# docker search alpine --filter is-official=true
NAME      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
alpine    A minimal Docker image based on Alpine Linux…   0         [OK]

Pull Alpine Linux image from Docker Hub.

# docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
213ec9aee27d: Pull complete
Digest: sha256:bc41182d7ef5ffc53a40b044e725193bc10142a1243f395ee852a8d9730fc2ad
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest

List down the locally available container images on your Docker Host.

# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
alpine       latest    9c6f07244728   2 months ago   5.54MB

Create a Container from Alpine Linux image, acquire a shell and execute some test commands thereon.

# docker run -it --rm alpine /bin/sh
/ # cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.16.2
PRETTY_NAME="Alpine Linux v3.16"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"
/ # uname -r
5.14.0-70.30.1.el9_0.x86_64
/ # exit

Read Also:

Final Thoughts

Congratulations on successfully learning how to install Docker on Rocky Linux 9! With Docker up and running, you’re now equipped with a powerful tool for containerizing your applications and streamlining your development and deployment workflows. Explore the world of containerization with confidence, knowing that Docker provides a scalable and efficient platform for building, shipping, and running your applications. Happy containerizing! Docker: Up & Running: Shipping Reliable Containers in Production (PAID LINK) by Sean P. Kane & Karl Matthias.

Exit mobile version