Install and Use Docker on AlmaLinux 9 | Comprehensive Guide

This tutorial on the Orcacore website intends to teach you How To Install and Use Docker on AlmaLinux 9. Docker is a software platform for building applications based on containers—small and lightweight execution environments that make shared use of the operating system kernel but otherwise run in isolation from one another.

To learn more about Docker, you can visit What Docker is and How Does it Work. Now proceed to the guide steps below to complete the Docker setup on AlmaLinux 9.

Steps To Install and Use Docker on AlmaLinux 9

To Install Docker on Almalinux 9, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide, the Initial Server Setup with AlmaLinux 9.

1. Install Docker on Almalinux 9

You need to update and upgrade the system’s package repository with the following command:

sudo dnf update -y && sudo dnf upgrade -y

Now you need to install the EPEL repository on AlmaLinux 9 with the following command:

sudo dnf install epel-release -y

If the podman and buildah packages exist, you need to remove them with the following command:

sudo dnf remove podman buildah

Then, you need to add the official Docker CE repository on AlmaLinux 9 with the following command:

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

At this point, install the Docker-CE package on AlmaLinux 9 with the following command:

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

Start and Enable Docker Service

When your installation is completed, start and enable the Docker service with the following command:

# sudo systemctl start docker.service
# sudo systemctl enable docker.service

To check that your service is active and running, run the following command:

sudo systemctl status docker

In your output, you will see:

Start and Enable Docker Service

Add User To the Docker Group

Here your service is active and running. Now you have the docker command-line utility.

Note: To run Docker commands, you need to log in as a non-root user with root privileges. or you can run a command with a user that is in a docker group that is created during the installation of Docker.

If you don’t want to use Sudo to run docker commands, you need to add your user to the docker group. To do this, run the following command:

sudo usermod -aG docker $(whoami)

At this point, log out of your server and then back in with the same user to enable these changes.

If you need to add a user to the docker group that you’re not logged in as, run the following command:

sudo usermod -aG docker username

Let’s see how to use docker on AlmaLinux 9.

2. How To Use Docker Command Line Utility on AlmaLinux 9?

After the installation of Docker on AlmaLinux 9 is finished, let’s see how to use the docker command-line utility. The syntax of the Docker command is like this:

docker [option] [command] [arguments]

Run the command below to see the options and available commands on the docker:

docker

In your output, you will see:

Use Docker Command Line Utility

Work with Docker images

The Docker Image is a portable file that contains a set of instructions that specify which software components the Container should run and how to run it.

At this point, let’s try to download and run the “hello-world” Docker image from the Docker hub. For this execute the docker command with the subcommand run like the following command:

sudo docker run hello-world

In your output, you should see:

Output
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:62af9efd515a25f84961b70f973a798d2eca956b1b2b026d0a4a63a3b0b6a3f2
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

Also, you can search for a Docker image if the image exists or is not in the Docker Hub. For example, we search for the AlmaLinux :

sudo docker search almalinux
Output
NAME                       DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
almalinux                  The official build of AlmaLinux OS.             85        [OK]
almalinux/almalinux        DEPRECATION NOTICE: This image is deprecated…   9    
almalinux/8-micro          AlmaLinux OS 8 official micro container image   2    
almalinux/podman                                                           1    
almalinux/mirror_service   AlmaLinux OS mirror service.                    1    
...

After you find the docker image that you want, use the pull subcommand to get your docker image:

sudo docker pull almalinux
Output
Using default tag: latest
latest: Pulling from library/almalinux
9589bd88d106: Pull complete
Digest: sha256:c8369022fa04c7d8f3c0504d4732fabf402ed756753d47291af5798c7910f7bd
Status: Downloaded newer image for almalinux:latest
docker.io/library/almalinux:latest

When the image is downloaded successfully, you can run the image with the following command:

sudo docker run almalinux

Now, you can list docker images with the following command:

sudo docker images

You will see:

Output
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
almalinux     latest    d1c25ed4de19   3 weeks ago     189MB
hello-world   latest    feb5d9fea6a5   12 months ago   13.3kB

You need to know about Docker containers too. Let’s see how Docker containers work on AlmaLinux 9.

Run a Docker container

Against virtual machines, are containers. They can be the best replacement for virtual machines. Containers separate the executive environments and share the operating system’s core.

To run the container with an Almalinux image, run the command below:

sudo docker run -it almalinux

Note: -it switch gives you interactive shell access into the container.

Your output should be similar to this:

[reita@124c67e3fdad /]#

Important Note: Remember the container ID. Here it is 124c67e3fdad.

Now you can run any command inside the container. For example, install the MariaDB server in the running container. No need to run any command with sudo, because you’re operating inside the container with root privileges.

To install MariaDB in the running container, use the following command:

dnf install mariadb

Commit changes in a container to a Docker image

In this step, you learn how to save the state of a container as a new Docker image on AlmaLinux 9. After you installed MariaDB in the Almalinux container, now you have a container running off an image, but the container is different from the image you used to create it.

First of all, you need to exit from it to save the state of the container as a new Docker image.

exit

Then, run the command below:

sudo docker commit -m "What did you do to the image" -a "Author Name" container-id repository/new_image_name

For example:

sudo docker commit -m "install mariadb" -a "reita" 124c67e3fdad almalinux1

Note: Remember to replace the container ID with your own.

Now you can list your docker images:

sudo docker images

Your output should be similar to this:

Output
REPOSITORY    TAG       IMAGE ID       CREATED          SIZE
almalinux1    latest    6b6efda1231c   14 seconds ago   324MB
almalinux     latest    d1c25ed4de19   3 weeks ago      189MB
hello-world   latest    feb5d9fea6a5   12 months ago    13.3kB

The size difference means the changes were made.

How to List Docker containers

In this step, we want to show how to list Docker containers on AlmaLinux 9. To see active containers run the following command:

docker ps
Output
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

You can see all containers including active and non-active with the command below:

docker ps -a
Output
CONTAINER ID   IMAGE         COMMAND       CREATED          STATUS                      PORTS     NAMES
124c67e3fdad   almalinux     "/bin/bash"   5 minutes ago    Exited (0) 2 minutes ago              vibrant_villani
a16d33ad4ec9   almalinux     "/bin/bash"   5 minutes ago    Exited (0) 5 minutes ago              test
b6e386670a79   almalinux     "/bin/bash"   13 minutes ago   Exited (0) 13 minutes ago             jovial_noether
f9d44538d565   almalinux     "/bin/bash"   15 minutes ago   Exited (0) 15 minutes ago             hardcore_merkle
114c9d1bed34   hello-world   "/hello"      18 minutes ago   Exited (0) 18 minutes ago             determined_lichterman

If you want to see the latest container you created type:

docker ps -l

To stop a running or active container run the following command:

docker stop container-id

Note: The container-id can be found in the output from the docker ps command.

3. Push Docker images to a Docker repository

After you create a new image from an existing image, you may want to share it with a few of your friends, the whole world on Docker Hub, or other Docker registries that you have access to. To push an image to Docker Hub or any other Docker registry, you must have an account there.

To have an account on Docker Hub, you need to register at Docker Hub.

If you want to log in to the Docker Hub, you will be asked for authentication :

docker login -u docker-registry-username

If you enter the correct password, authentication should succeed. Then you may push your own image using the following command:

docker push docker-registry-username/docker-image-name

It will take a little time to complete. After you push an image to a registry, it should be listed on your account’s dashboard.

Note: If a push attempt results in an error of this sort, login, then repeat the push attempt.

Conclusion

At this point, you have learned what Docker is and you can easily install it on your server and use it. Docker on AlmaLinux 9 helps run apps in containers, making them easy to manage, move, and scale while keeping the system stable and secure.

Hope you enjoy this article about How to Install and Use Docker on AlmaLinux 9. For more guides, you can visit the Docker Tutorials.

Please follow us on Facebook, Instagram, and YouTube.

You may also like these articles:

Install Caddy Web Server on AlmaLinux 9

Install and Configure XRDP on AlmaLinux 9

Install Python 3.13 on AlmaLinux 9

Share your love

One comment

Comments are closed.

Stay informed and not overwhelmed, subscribe now!