How to Install Docker on Rocky Linux 10 A Step-by-Step Guide

How to Install Docker on Rocky Linux 10: A Comprehensive Enterprise Guide
At revWhiteShadow, we understand the critical importance of establishing a robust and reliable environment for your containerized workloads. Rocky Linux 10, with its strong Enterprise Linux foundation, provides an excellent platform for deploying and managing applications using Docker. In this in-depth guide, we will walk you through the meticulous process of installing Docker on your Rocky Linux 10 system, ensuring a smooth and efficient setup for all your containerization needs. We aim to provide a level of detail and clarity that surpasses existing resources, enabling you to confidently leverage the power of Docker.
Understanding the Benefits of Docker on Rocky Linux 10
Before we delve into the installation process, it’s crucial to appreciate why this combination is so powerful. Rocky Linux 10, a community-driven distribution that serves as a free, enterprise-class binary-compatible fork of Red Hat Enterprise Linux (RHEL), offers unparalleled stability, security, and long-term support. When coupled with Docker, a leading platform for developing, shipping, and running applications in containers, you unlock a world of advantages.
Containers package an application and its dependencies together, ensuring that it runs consistently across different computing environments. This eliminates the “it works on my machine” problem and simplifies deployment and management. Docker’s lightweight nature means that containers consume fewer resources than traditional virtual machines, allowing for higher density and more efficient utilization of your Rocky Linux 10 server’s capabilities. Furthermore, Docker promotes portability, scalability, and agility, making it an indispensable tool for modern software development and operations.
Prerequisites for a Successful Docker Installation
To ensure a seamless installation of Docker on your Rocky Linux 10 system, a few prerequisites are essential. We will outline these requirements clearly to prevent any potential roadblocks during the process.
System Requirements
While Docker is designed to be resource-efficient, certain minimum specifications will contribute to optimal performance. We recommend a system with at least:
- 2 GB of RAM: While Docker can run on less, this amount ensures smoother operation of both the host system and multiple containers.
- A multi-core CPU: A modern processor will significantly speed up container startup times and overall application responsiveness.
- Sufficient disk space: The amount of disk space required will depend on the number and size of container images you intend to store and run. We suggest a minimum of 20 GB of free disk space, with more recommended for extensive use.
- A stable internet connection: This is crucial for downloading Docker packages and container images.
User Privileges
Throughout this guide, we will be executing commands that require elevated privileges. Therefore, you will need to be logged in as the root user or have access to commands via sudo. It is our standard practice at revWhiteShadow to use sudo
for individual commands to maintain a higher level of security and accountability.
System Updates
Before proceeding with the Docker installation, it is highly advisable to ensure that your Rocky Linux 10 system is fully up-to-date. This minimizes the risk of compatibility issues and ensures you have the latest security patches.
To update your system, execute the following commands:
sudo dnf update -y
This command will refresh the package repository information and then upgrade all installed packages to their latest available versions. The -y
flag automatically confirms any prompts, streamlining the update process. Allow ample time for this operation to complete, as it may download and install a significant number of packages.
Uninstalling Previous Docker Versions (If Applicable)
In the event that you have previously attempted to install Docker or any related packages from sources other than the official repositories, it is imperative to remove them before proceeding. This prevents conflicts and ensures a clean installation.
Execute the following commands to remove any older Docker installations:
sudo dnf remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine \
podman \
runc
This comprehensive list targets common Docker and container-related packages. If you encounter an error indicating that a package is not installed, it simply means it was not present on your system, and you can safely ignore it.
Installing Docker Engine on Rocky Linux 10: The Definitive Method
Our preferred and most reliable method for installing Docker on Rocky Linux 10 involves utilizing the official Docker repositories. This ensures that you receive the latest stable versions and benefit from ongoing updates directly from Docker.
Setting Up the Docker Repository
The first step is to add the official Docker repository to your system’s package manager configuration. This allows dnf
to find and install Docker.
Create a new repository file named docker-ce.repo
in the /etc/yum.repos.d/
directory using your preferred text editor, such as nano
or vim
.
sudo nano /etc/yum.repos.d/docker-ce.repo
Paste the following content into the file. Ensure that the enabled
parameter is set to 1
to activate the repository.
[docker-ce]
name=Docker CE Stable - BaseOS
baseurl=https://download.docker.com/linux/centos/8/\$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
Explanation of the Repository File:
[docker-ce]
: This is the repository ID.name
: A human-readable name for the repository.baseurl
: The URL where the Docker CE packages are located. We are specifying the repository for CentOS 8, which is compatible with Rocky Linux 10 due to their shared RHEL heritage.\$basearch
is a variable thatdnf
will automatically substitute with your system’s architecture (e.g.,x86_64
).enabled=1
: This directive ensures that the repository is active and will be used bydnf
.gpgcheck=1
: This specifies that package signatures should be verified using GPG keys. This is a critical security measure.gpgkey
: The URL of the GPG key used to sign the Docker packages.
After pasting the content, save the file and exit the text editor. If you are using nano
, press Ctrl+X
, then Y
, and finally Enter
.
Installing Docker Engine, Containerd, and Docker Compose
With the repository configured, we can now install the core Docker components. This includes Docker Engine, the container runtime (containerd), and Docker Compose, a tool for defining and running multi-container Docker applications.
Execute the following command to install these essential packages:
sudo dnf install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y
Breakdown of the Installation Command:
sudo dnf install
: This is the command to install packages using the DNF package manager.docker-ce
: This is the Docker Community Edition engine, the core Docker daemon.docker-ce-cli
: This installs the Docker command-line interface, which you will use to interact with Docker.containerd.io
: This installs containerd, a high-level container runtime that Docker relies on.docker-compose-plugin
: This installs the Docker Compose plugin, allowing you to usedocker compose
commands.
This command will download and install all the necessary dependencies. Again, the -y
flag will automatically confirm the installation.
Starting and Enabling the Docker Service
Once the installation is complete, you need to start the Docker daemon and configure it to start automatically on system boot.
Start the Docker service using the systemctl
command:
sudo systemctl start docker
To ensure Docker starts automatically when your Rocky Linux 10 system boots up, enable the service:
sudo systemctl enable docker
You can check the status of the Docker service to confirm it is running correctly:
sudo systemctl status docker
You should see output indicating that the service is active (running). Press q
to exit the status view.
Verifying Your Docker Installation
A crucial step in any software installation is verification. We need to confirm that Docker is functioning as expected.
Running the “Hello World” Container
Docker provides a convenient test image called hello-world
that allows you to verify that Docker can communicate with its daemon and that your containers can run properly.
Execute the following command:
sudo docker run hello-world
If Docker is installed correctly, you will see a message similar to this:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
...
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.
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 our introductory example, "docker run -it ubuntu bash".
Experiments may be bad. But experiments are the only way to learn.
This output confirms that Docker is installed, running, and capable of pulling images and executing containers.
Checking Docker Version
You can also verify the installed Docker version using the following command:
sudo docker version
This command will display information about both the Docker Client and the Docker Engine, including their respective versions. This is useful for troubleshooting and ensuring you are running a specific version.
Managing Docker with Non-Root Users
By default, Docker commands require sudo
. For convenience and to allow non-root users to manage Docker containers, you can add your user to the docker
group. This grants the user the necessary permissions.
Important Security Note: Adding a user to the docker
group effectively grants them root-level privileges on the host system. Ensure you understand the implications of this before proceeding.
To add your current user to the docker
group, execute:
sudo usermod -aG docker $USER
After executing this command, you will need to log out and log back in for the group membership changes to take effect. Alternatively, you can run the following command to apply the group changes to your current shell session without logging out:
newgrp docker
Once you have logged back in or run newgrp docker
, you should be able to run Docker commands without using sudo
. For instance:
docker run hello-world
This streamlined approach makes interacting with Docker much more fluid for everyday tasks.
Configuring Docker Daemon Settings (Optional but Recommended)
The Docker daemon can be configured to adjust its behavior, such as specifying where container images are stored or setting up network configurations. These configurations are typically managed through the daemon.json
file.
Locating the Docker Daemon Configuration File
The primary configuration file for the Docker daemon is located at /etc/docker/daemon.json
. If this file does not exist, you can create it.
sudo nano /etc/docker/daemon.json
Common Docker Daemon Configuration Options
Here are a few common and useful configuration options you might consider:
data-root
: Specifies the directory where Docker stores its images, containers, and volumes. By default, this is/var/lib/docker
. If you have a separate partition or a larger drive for storage, you might want to change this.{ "data-root": "/path/to/your/docker/data" }
Remember to ensure that the specified directory exists and that the Docker daemon has the necessary permissions to write to it.
storage-driver
: Allows you to specify the storage driver Docker uses. The default and recommended driver for most Linux systems isoverlay2
. You generally do not need to change this unless you have specific requirements or encounter issues with the default.{ "storage-driver": "overlay2" }
log-driver
andlog-opts
: Configure how container logs are managed.json-file
is the default, but you can set up other logging drivers likesyslog
,journald
, or even remote logging solutions. You can also set maximum log file size and rotation.{ "log-driver": "json-file", "log-opts": { "max-size": "10m", "max-file": "3" } }
This example configures logs to be stored as JSON files, with each file capped at 10 megabytes and a maximum of 3 log files kept.
Applying Daemon Configuration Changes
After making any modifications to /etc/docker/daemon.json
, you must restart the Docker service for the changes to take effect.
sudo systemctl restart docker
It is always a good practice to check the Docker service status again after a restart to ensure it starts without errors.
Managing Docker Containers and Images
With Docker installed and running, let’s briefly touch upon some fundamental commands for managing your containerized applications.
Pulling Docker Images
To run an application in a container, you first need to download its image from a registry, the most common being Docker Hub.
docker pull ubuntu:latest
This command downloads the latest Ubuntu image.
Running Docker Containers
To run a container from an image:
docker run -it --name my-ubuntu-container ubuntu:latest
-it
: Allocates a pseudo-TTY and keeps stdin open, allowing you to interact with the container.--name my-ubuntu-container
: Assigns a specific name to your container for easier management.
Listing Running Containers
To see all containers that are currently running:
docker ps
Listing All Containers (Including Stopped Ones)
To see all containers, including those that have exited:
docker ps -a
Stopping and Starting Containers
To stop a running container:
docker stop my-ubuntu-container
To start a stopped container:
docker start my-ubuntu-container
Removing Containers
To remove a stopped container:
docker rm my-ubuntu-container
You can also force the removal of a running container (use with caution):
docker rm -f my-ubuntu-container
Listing Docker Images
To view all the Docker images you have downloaded:
docker images
Removing Docker Images
To remove an image:
docker rmi ubuntu:latest
Troubleshooting Common Docker Installation Issues
While this guide aims to be comprehensive, you might encounter specific issues. Here are some common problems and their solutions.
“Cannot connect to the Docker daemon. Is the docker daemon running on this host?”
This is the most frequent error and indicates that the Docker service is either not running or not accessible.
Check Docker Service Status:
sudo systemctl status docker
If it’s not active, start and enable it:
sudo systemctl start docker sudo systemctl enable docker
Permissions Issue (if not using sudo): If you’ve added your user to the
docker
group, ensure you have logged out and back in. Runningnewgrp docker
in your current session can also apply the group changes.
Package Not Found Errors During Installation
If dnf
reports that it cannot find the Docker packages, double-check the /etc/yum.repos.d/docker-ce.repo
file for typos or incorrect URLs. Ensure the repository is enabled.
Conflicting Packages
If you encounter errors about conflicting packages, it might be due to remnants of older installations. Revisit the Uninstalling Previous Docker Versions section and ensure all old packages are removed.
Conclusion
By meticulously following this step-by-step guide, you have successfully installed Docker Engine on your Rocky Linux 10 system. This robust setup provides a solid foundation for leveraging the power and flexibility of containerized applications. At revWhiteShadow, we are committed to providing you with the most accurate and detailed information to empower your technological endeavors. With Docker now at your disposal on this stable enterprise-grade operating system, you are well-equipped to streamline your development workflows, enhance application portability, and achieve greater operational efficiency. Remember to keep your Docker installation and Rocky Linux 10 system updated regularly to benefit from the latest features and security patches. We encourage you to explore the vast ecosystem of Docker images and tools available to further optimize your containerization strategy.