Install Docker on Rocky Linux 9 | Free Containerization Tool

In this tutorial, we want to teach you How To Install Docker on Rocky Linux 9. Docker is a free and open-source containerization tool that enables developers to package their applications into a container. Later that container image can be used to deploy and run applications on a public or private cloud.

You can now proceed to the guide steps below on the Orcacore website to install Docker CE on Rocky Linux 9.

Steps To Install and Use Docker CE on Rocky Linux 9

To install Docker on Rocky Linux 9 you need some requirements first.

Requirements for Docker CE on Rocky Linux 9:

  • A fresh Rocky Linux 9.

1. Install Docker on Rocky Linux 9

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

sudo dnf update && dnf upgrade

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

sudo dnf install epel-release -y

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

sudo dnf remove podman buildah

Add Docker CE Repository

Then, you need to add the official Docker CE repository on Rocky Linux 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 Rocky Linux 9 with the following command:

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

Manage 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:

Install Docker on Rocky Linux 9 - Docker Service Status

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

2. How To Run Docker Commands?

Note: As we mentioned before to run the 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 which 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 Rocky Linux 9.

3. How To Use Docker CE on Rocky Linux 9?

After the installation of Docker CE on Rocky Linux 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:

Docker Options and Commands

4. How To Work with Docker Images on Rocky Linux 9?

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:

Work with Docker Images on Rocky Linux 9

Search for Docker Images

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

sudo docker search almalinux
Search for Docker Images

Pull Docker Images

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

sudo docker pull almalinux
Pull Docker Images

Run Docker Images

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

sudo docker run almalinux

List Docker Images

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

sudo docker images

You will see:

List Docker Images

At this point, you need to know about docker containers too. Let’s see how Docker containers work on Rocky Linux 9.

5. How to Run a Docker Container on Rocky Linux 9?

Against virtual machines, are containers. They can be the best replacement for virtual machines. Containers separate the executive environments and share the operation 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:

[root@4c185a4e03f4 /]#

Important Note: Remember the container ID. Here it is 4c185a4e03f4.

Now you can run any command inside the container. For example, install the MySQL 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 MySQL in the running container use the following command:

dnf install mysql

6. 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 Rocky Linux 9.

After you installed MySQL 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 mysql" -a "sam" 4c185a4e03f4 almalinux

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:

Commit changes in a container to a Docker image

The size difference means the changes were made.

7. List Docker Containers on Rocky Linux 9

In this step, we want to show how to list Docker containers on Rocky Linux 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
List Docker Containers

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.

8. 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 to Install and Use Docker CE on Rocky Linux 9. Also, you have learned to work with docker commands, pull images, list containers, etc.

Hope you enjoy it. You may also interested in these articles:

Enable RPM Fusion Repository on Rocky Linux 9

How To Install WineHQ on Rocky Linux 9

Set up NTP Server and Client on Rocky Linux 9

Share your love

Stay informed and not overwhelmed, subscribe now!