The concept of containerization has been in continuance for a number of decades, but the emergence of an open-source Docker Engine hastened its accretion. Many organizations around the world have now adopted this technology to create and modernize existing applications for the cloud.Containerization can be defined as the packaging of the required software code to run a lightweight executable referred to as a container. A container is a lightweight and portable unit that is able to run in an isolated environment. The container ships the operating system, libraries, and dependencies required to run an application.
Docker is one of the popularly used containerization platform tools although there are some other tools such as Podman(developed by RedHat), AWS Fargate, Google Kubernetes Engine, Amazon ECS, LXC e.t.c. Using Docker, open can develop, test, and deploy applications in containers. This containerization platform has been in existence since 2013, introduced as an industry-standard tool with simple developer tools and a universal packaging approach.
There are two main editions of Docker, these are:
- Docker community edition (Docker CE): This is a free and open-source edition ideal for individual developers and small teams that want to get started with Docker and run experiments.
- Docker enterprise edition (Docker EE): This edition is designed for enterprise development and IT teams for building, shipping, and running applications in production environments. This edition offers more features and capabilities that include image security scanning, container app management, certified infrastructure, plugins, and ISV containers e.t.c
In this guide, we will cover all the steps required to install and use Docker CE on Rocky Linux 9 / AlmaLinux 9
Installation Requirements
To be able to install and run Docker, you need a system that meets the below requirements:
- 64-bit Operating system.
- Linux Kernel version should be 3.10 or above
- user account with
sudo
privileges - VT (virtualization technology) support enabled on your system BIOS
- Internet connection
Check the Kernel and architecture on Rocky Linux 9 / AlmaLinux 9.
$ uname -a
Linux k8sworkstation.cloudspinx.com 5.14.0-427.13.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Wed May 1 19:11:28 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
1. Add Docker Repository
To be able to install Docker and the required package dependencies on Rocky Linux 9 / AlmaLinux 9, we need to add the Docker repository to the system.
First, update the system using the command:
sudo dnf --refresh update
Add the Docker CE repository using the command:
sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
2. Install Docker CE
Once the repositories have been added to the system, Docker CE and all the required dependencies can be installed using the below commands.
First, remove older versions using the command:
sudo dnf remove docker docker-common docker-selinux docker-engine
Install the required dependency packages:
sudo dnf -y install device-mapper-persistent-data lvm2
Install Docker CE using the command:
sudo dnf install docker-ce docker-ce-cli containerd.io docker-compose-plugin
It fou get an error with conflicting packages during the installation, you can run the above command with the --allowerasing
to erase the conflicting packages:
sudo dnf install docker-ce docker-ce-cli containerd.io docker-compose-plugin --allowerasing
Dependency Tree:
Docker CE Stable - x86_64 41 kB/s | 58 kB 00:01
Dependencies resolved.
==========================================================================================================================================================================================================
Package Architecture Version Repository Size
==========================================================================================================================================================================================================
Installing:
containerd.io x86_64 1.7.22-3.1.el9 docker-ce-stable 43 M
docker-ce x86_64 3:27.3.1-1.el9 docker-ce-stable 27 M
docker-ce-cli x86_64 1:27.3.1-1.el9 docker-ce-stable 8.0 M
docker-compose-plugin x86_64 2.29.7-1.el9 docker-ce-stable 13 M
Installing dependencies:
container-selinux noarch 3:2.229.0-1.el9 appstream 56 k
fuse-overlayfs x86_64 1.13-1.el9 appstream 66 k
fuse3 x86_64 3.10.2-8.el9 appstream 53 k
fuse3-libs x86_64 3.10.2-8.el9 appstream 90 k
libslirp x86_64 4.4.0-7.el9 appstream 68 k
slirp4netns x86_64 1.2.3-1.el9 appstream 46 k
tar x86_64 2:1.34-6.el9_4.1 baseos 876 k
Installing weak dependencies:
docker-buildx-plugin x86_64 0.17.1-1.el9 docker-ce-stable 14 M
docker-ce-rootless-extras x86_64 27.3.1-1.el9 docker-ce-stable 4.4 M
Transaction Summary
==========================================================================================================================================================================================================
Install 13 Packages
Total download size: 110 M
Installed size: 430 M
Is this ok [y/N]: y
To verify the installation, run the command:
$ docker --version
Docker version 27.3.1, build ce12230
Now start and enable Docker on Rocky Linux 9 / AlmaLinux 9.
sudo systemctl enable --now docker
Verify if the service is running:
$ systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: disabled)
Active: active (running) since Fri 2024-11-08 01:01:49 EAT; 13s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 39133 (dockerd)
Tasks: 10
Memory: 26.1M
CPU: 445ms
CGroup: /system.slice/docker.service
└─39133 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Nov 08 01:01:47 k8sworkstation.chaileo.net systemd[1]: Starting Docker Application Container Engine...
3. Add User to Docker Group
In order to run the docker commands without sudo
command, you need to add your system user to the Docker group.
This can be done using the commands:
sudo usermod -aG docker $USER
newgrp docker
Verify this using the command:
$ id $USER
uid=0(root) gid=0(root) groups=0(root),990(docker)
As seen, the user has now been added to the docker group. You are now able to execute docker commands without using sudo
Obtainer the detailed Docker version information;
$ docker version
Client: Docker Engine - Community
Version: 27.3.1
API version: 1.47
Go version: go1.22.7
Git commit: ce12230
Built: Fri Sep 20 11:42:48 2024
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 27.3.1
API version: 1.47 (minimum version 1.24)
Go version: go1.22.7
Git commit: 41ca978
Built: Fri Sep 20 11:41:09 2024
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.7.22
GitCommit: 7f7fdf5fed64eb6a7caf99b3e12efcf9d60e311c
runc:
Version: 1.1.14
GitCommit: v1.1.14-0-g2c9f560
docker-init:
Version: 0.19.0
GitCommit: de40ad0
4. Testing Docker Engine
Once installed, you can now use Docker to run your desired containers. For this guide, we will demonstrate this by pulling and running a sample hello_world container.
The below command will pull and run the container on Docker:
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:d211f485f2dd1dee407a80973c8f129f00d54604d2c90732e8e320e5038a0348
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/
5. Pull a Docker Container Image
The docker run
command will pull and run the application. But if you want to pull an image, you will use the docker pull
command and specify the image. For example:
docker pull ubuntu
Once pulled, the available images can be checked using the command:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 59ab366372d5 3 weeks ago 78.1MB
hello-world latest d2c94e258dcb 18 months ago 13.3kB
You can now use the image to run a container. For example running Ubuntu in a docker container, execute the command:
$ docker run -it ubuntu
root@1f240506aadf:/# cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.1 LTS (Noble Numbat)"
VERSION_CODENAME=noble
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=noble
LOGO=ubuntu-logo
root@1f240506aadf:/#
6. Build Docker Container Images
Docker also allows one to build custom images from a file. The created images can then be stored locally or pushed to a registry for future use.
To create an image, you need to have a Dockerfile created as shown;
vim Dockerfile
In the file, add the lines that define the activities and dependencies to be captured in the image. For example:
FROM ubuntu:20.04
RUN apt-get update -y
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get install -y gnupg apt-transport-https apt-utils wget
RUN echo "deb https://notesalexp.org/tesseract-ocr5/focal/ focal main" \
|tee /etc/apt/sources.list.d/notesalexp.list > /dev/null
RUN wget -O - https://notesalexp.org/debian/alexp_key.asc | apt-key add -
RUN apt-get update -y
RUN apt-get install tesseract-ocr -y
RUN apt install imagemagick -y
ENTRYPOINT ["tesseract"]
RUN tesseract -v
The above file specifies the container image to be build with Ubuntu OS and install an application called tesseract-ocr with all the required dependencies.
To build the container, run the command:
$ docker build . -t tesseract:5
[+] Building 253.9s (13/13) FINISHED docker:default
=> [internal] load build definition from dockerfile 0.8s
=> => transferring dockerfile: 575B 0.0s
=> [internal] load metadata for docker.io/library/ubuntu:20.04 5.4s
=> [internal] load .dockerignore 0.9s
=> => transferring context: 2B 0.0s
=> [1/9] FROM docker.io/library/ubuntu:20.04@sha256:8e5c4f0285ecbb4ead070431d29b576a530d3166df73ec44affc1cd27555141b 7.7s
=> => resolve docker.io/library/ubuntu:20.04@sha256:8e5c4f0285ecbb4ead070431d29b576a530d3166df73ec44affc1cd27555141b 0.3s
=> => sha256:e5a6aeef391a8a9bdaee3de6b28f393837c479d8217324a2340b64e45a81e0ef 424B / 424B 0.0s
=> => sha256:6013ae1a63c2ee58a8949f03c6366a3ef6a2f386a7db27d86de2de965e9f450b 2.30kB / 2.30kB 0.0s
=> => sha256:8e5c4f0285ecbb4ead070431d29b576a530d3166df73ec44affc1cd27555141b 6.69kB / 6.69kB 0.0s
=> => sha256:d9802f032d6798e2086607424bfe88cb8ec1d6f116e11cd99592dcaf261e9cd2 27.51MB / 27.51MB 4.8s
=> => extracting sha256:d9802f032d6798e2086607424bfe88cb8ec1d6f116e11cd99592dcaf261e9cd2 1.7s
=> [2/9] RUN apt-get update -y 15.1s
=> [3/9] RUN apt-get install -y gnupg apt-transport-https apt-utils wget 30.8s
=> [4/9] RUN echo "deb https://notesalexp.org/tesseract-ocr5/focal/ focal main" |tee /etc/apt/sources.list.d/notesalexp.list > /dev/null 1.1s
=> [5/9] RUN wget -O - https://notesalexp.org/debian/alexp_key.asc | apt-key add - 2.5s
=> [6/9] RUN apt-get update -y 4.7s
=> [7/9] RUN apt-get install tesseract-ocr -y 116.0s
=> [8/9] RUN apt install imagemagick -y 59.4s
=> [9/9] RUN tesseract -v 4.4s
=> exporting to image 2.6s
=> => exporting layers 2.5s
=> => writing image sha256:92ac120fbda1c48c1e7d961861f740cff7139d5611e6df6040bca02bdab2f893 0.0s
=> => naming to docker.io/library/tesseract:5
The -t flag is used to add a tag to the created image. Once complete, verify the image created using the command:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tesseract 5 92ac120fbda1 3 minutes ago 323MB
ubuntu latest 59ab366372d5 3 weeks ago 78.1MB
hello-world latest d2c94e258dcb 18 months ago 13.3kB
You can now use the locally stored docker image to run a container:
$ docker run tesseract:5 -v
tesseract 5.4.1
leptonica-1.79.0
libgif 5.1.4 : libjpeg 8d (libjpeg-turbo 2.0.3) : libpng 1.6.37 : libtiff 4.1.0 : zlib 1.2.11 : libwebp 0.6.1 : libopenjp2 2.3.1
Found SSE4.1
Found OpenMP 201511
Found libarchive 3.4.0 zlib/1.2.11 liblzma/5.2.4 bz2lib/1.0.8 liblz4/1.9.2 libzstd/1.4.4
Found libcurl/7.68.0 OpenSSL/1.1.1f zlib/1.2.11 brotli/1.0.7 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh/0.9.3/openssl/zlib nghttp2/1.40.0 librtmp/2.3
Final Thoughts
Now you have Docker CE installed on Rocky Linux 9 / AlmaLinux 9, proceed and build, test, and deploy applications in containers as desired. I hope this was consequential.
Check out these other articles on Docker: