Docker is an open-source platform that automates the deployment, scaling, and management of applications in containers. Containers allow developers to package an application with all its dependencies and deliver it as a single package, which can be deployed on any system that supports containerization. In this tutorial, we will guide you through the process of installing Docker on CentOS Stream 9 and RHEL 9.
Prerequisites
- A freshly installed CentOS Stream 9 or RHEL 9 system.
- A user account with sudo privileges.
Step 1: Update the System
Before installing Docker, it is essential to update your system to ensure all the required packages and dependencies are up-to-date. Execute the following command:
sudo dnf update -y
Step 2: Install Required Dependencies
Next, install the necessary dependencies for Docker:
sudo dnf install -y yum-utils device-mapper-persistent-data lvm2
Step 3: Add Docker Repository
Now, add the Docker repository to your system. The configuration file is avaialble on Docker’s official site. The CentOS Stream 9 users execute the following command:
sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
For RHEL 9 users, the command will be:
sudo dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo
Step 4: Install Docker CE
With the Docker repository in place, you can now install Docker CE (Community Edition) using the following command:
sudo dnf install -y docker-ce --nobest
The --nobest
flag is used to install the highest version of Docker that satisfies the package’s dependencies.
Step 5: Enable and Start Docker Service
Once the installation is complete, enable the Docker service to start on boot and start the service immediately:
sudo systemctl enable --now docker
Step 6: Verify Docker Installation
To ensure that Docker is installed and running correctly, you can check its status with the following command:
sudo systemctl status docker
Additionally, you can verify the installed version by running:
sudo docker --version
Step 7: Configure Docker to Run Without Sudo (Optional)
By default, Docker requires sudo privileges to execute commands. If you want to run Docker commands without sudo, you can add your user to the “docker” group. Replace “your_username” with your actual username:
sudo usermod -aG docker your_username
Log out and log back in for the changes to take effect. Keep in mind that adding your user to the “docker” group gives the user root-level privileges. Make sure you understand the security implications before performing this step.
Conclusion
You have now successfully installed Docker on your CentOS Stream 9 or RHEL 9 system. You can start deploying and managing containerized applications using the Docker platform. To learn more about Docker and its usage, consult the official Docker documentation at https://docs.docker.com/.
1 Comment
On RHEL9 Getting the following error:
Docker CE Stable – x86_64 313 B/s | 381 B 00:01
Errors during downloading metadata for repository ‘docker-ce-stable’:
– Status code: 404 for https://download.docker.com/linux/rhel/9/x86_64/stable/repodata/repomd.xml (IP: 52.85.24.68)
Error: Failed to download metadata for repo ‘docker-ce-stable’: Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
And from here: https://forums.docker.com/t/unable-to-install-docker-on-rhel-9-2/136123/2 and here: https://download.docker.com/linux/rhel/9/
It appear there is no x86_64 package in the repo