Post

Install and configure Docker on CentOS Stream 9

Introduction –

Docker is a popular platform for developing, deploying, and running applications in containers. In this article, we will walk you through the steps to install Docker on CentOS 9, a popular Linux distribution.

Prerequisites

Before we begin, ensure that you have a CentOS 9 instance with root or sudo privileges. Additionally, ensure that your system is up-to-date by running the following command:

1
sudo yum update -y

Step 1: Install required dependencies

The first step in installing Docker on CentOS 9 is to install the necessary dependencies. Run the following command to install the yum-utils package, which provides the yum-config-manager utility:

1
sudo yum install -y yum-utils

Step 2: Add the Docker repository

Next, add the Docker repository to your CentOS 9 system using the following command:

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

Step 3: Install Docker Engine

After adding the Docker repository, you can proceed to install the Docker Engine. Run the following command to install Docker Engine along with the docker-compose-plugin and containerd.io packages:

1
sudo yum install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin

Step 4: Start and verify Docker installation

Once Docker Engine is installed, start the Docker service using the following command:

1
sudo systemctl start docker

To verify that Docker has been successfully installed, run the following command to download and run a test container:

1
sudo docker run hello-world

If Docker has been installed correctly, you should see the following output:

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

Step 5: Enable Docker service on boot

To ensure that the Docker service starts automatically on boot, run the following commands:

1
2
sudo systemctl enable docker.service
sudo systemctl enable containerd.service

Step 6: Manage Docker as a non-root user

It is recommended to manage Docker as a non-root user to improve security. To achieve this, create a new docker group using the following command:

1
sudo groupadd docker

Next, add the currently logged-in user to the docker group:

1
sudo usermod -aG docker $USER

Finally, reboot the system for the changes to take effect:

1
sudo reboot -h now

After the system reboots, try running Docker as the current user without sudo:

1
docker run hello-world

If you see the same output as before, Docker has been successfully installed and configured on your CentOS 9 system.

Conclusion

In this article, we have shown you how to install Docker on CentOS 9, enabling you to use Docker to deploy and manage containerized applications on your system. Remember to always manage Docker as a non-root user to improve security.

References

Referencees: https://docs.docker.com/engine/install/centos/

TLDR

Here are all the commands used in this article, grouped by section:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Prerequisites
sudo yum update -y

# Step 1: Install Required Dependencies
sudo yum install -y yum-utils

# Step 2: Add the Docker Repository
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

# Step 3: Install Docker Engine
sudo yum install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin

# Step 4: Start and Verify Docker Installation
sudo systemctl start docker
sudo docker run hello-world

# Step 5: Enable Docker Service at Boot
sudo systemctl enable docker.service
sudo systemctl enable containerd.service

# Step 6: Manage Docker as a Non-Root User
sudo groupadd docker
sudo usermod -aG docker $USER
sudo reboot -h now
docker run hello-world
This post is licensed under Apache License 2.0 by the author.