How to Install Docker on AlmaLinux 10 A Step-by-Step Guide

How to Install Docker on AlmaLinux 10: The Definitive Guide from revWhiteShadow
At revWhiteShadow, we understand the critical need for robust and reliable containerization solutions, especially for users migrating from or building upon Enterprise Linux distributions. AlmaLinux 10, a community-driven, open-source operating system, offers a stable and secure foundation, making it an excellent choice for deploying modern applications. Integrating Docker, the industry-leading platform for building, shipping, and running applications in containers, onto AlmaLinux 10 is a straightforward process. This comprehensive guide will walk you through every necessary step to install Docker on AlmaLinux 10, ensuring you have a fully functional container runtime environment ready for your development and deployment needs. Our aim at revWhiteShadow is to provide you with the most detailed and actionable information, enabling you to achieve your technical goals with confidence.
Understanding Docker and its Significance for AlmaLinux 10
Before we delve into the installation process, it’s beneficial to briefly touch upon what Docker is and why it’s so valuable, particularly in the context of AlmaLinux 10. Docker revolutionizes application deployment by encapsulating applications and their dependencies into portable units called containers. These containers provide an isolated environment, ensuring that applications run consistently across different machines and infrastructure, from a developer’s laptop to a production server.
For users of Enterprise Linux systems like AlmaLinux 10, Docker brings several key advantages:
- Consistency: Eliminates the “it works on my machine” problem by packaging applications and their environments together.
- Portability: Containers can be moved and run on any system that supports Docker, regardless of the underlying operating system.
- Efficiency: Containers share the host operating system’s kernel, making them lighter and faster to start than traditional virtual machines.
- Isolation: Processes within a container are isolated from the host system and other containers, enhancing security and stability.
- Scalability: Docker integrates seamlessly with orchestration tools like Kubernetes, facilitating the scaling of applications.
AlmaLinux 10, with its commitment to stability and long-term support, provides an ideal platform for running these efficient and consistent containerized workloads. By following this guide from revWhiteShadow, you’ll be well on your way to leveraging the power of Docker on your AlmaLinux 10 system.
Prerequisites for Installing Docker on AlmaLinux 10
To ensure a smooth and successful installation of Docker on your AlmaLinux 10 system, please ensure you have met the following prerequisites:
- A System Running AlmaLinux 10: This guide assumes you have a functioning AlmaLinux 10 installation. Ensure your system is up-to-date.
- Root or Sudo Privileges: You will need administrative privileges to install software packages and manage system services. We will use the
sudo
command for most operations, which requires your user to be in thesudoers
file. - Internet Connectivity: A stable internet connection is required to download Docker packages and their dependencies from official repositories.
- Basic Command-Line Familiarity: While this guide is detailed, a basic understanding of navigating the Linux command line and executing commands will be helpful.
We recommend performing a system update before proceeding to ensure all packages are current. You can do this with the following commands:
sudo dnf update -y
This command updates all installed packages to their latest versions, ensuring compatibility and security.
Step 1: Uninstalling Previous Docker Versions (If Applicable)
Before installing the latest version of Docker, it’s crucial to remove any older versions or conflicting packages that might already be present on your AlmaLinux 10 system. This prevents potential conflicts and ensures a clean installation.
We will use the dnf
package manager to remove these packages. Execute the following commands:
sudo dnf remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine \
podman \
runc
Explanation of the command:
sudo dnf remove
: This is the command to remove packages using the DNF package manager with superuser privileges.docker
,docker-client
,docker-common
,docker-engine
, etc.: These are common package names associated with older installations of Docker or its related components.podman
,runc
: These are alternative container management tools that might be installed by default on AlmaLinux. While Podman is a capable alternative, this guide focuses on Docker. Removing them ensures a clean slate for our Docker installation.
After running the command, DNF will list the packages to be removed and ask for confirmation. Type y
and press Enter to proceed. If no Docker packages are found, DNF will simply report that.
Step 2: Setting Up the Docker Repository
To install Docker, we need to add the official Docker CE (Community Edition) repository to your AlmaLinux 10 system. This ensures you are downloading the most stable and up-to-date version directly from Docker.
First, we’ll install the dnf-utils
package, which provides the dnf config-manager
utility. This utility simplifies the process of adding and managing software repositories.
sudo dnf install -y dnf-utils
Now, we use dnf config-manager
to add the stable Docker repository.
sudo dnf config-manager --add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
Explanation of the command:
sudo dnf config-manager
: This command allows us to manage DNF repositories with administrative privileges.--add-repo
: This option tellsdnf config-manager
to add a new repository.https://download.docker.com/linux/centos/docker-ce.repo
: This is the URL pointing to the Docker CE repository configuration file for CentOS, which is compatible with AlmaLinux as they are both RHEL-based distributions.
This command downloads and installs the repository configuration file, making the Docker CE packages available to your system’s package manager.
Step 3: Installing Docker Engine on AlmaLinux 10
With the repository set up, we can now proceed to install Docker Engine. This includes the Docker daemon, the Docker client, and the Docker Compose plugin.
We will use the dnf install
command to install the specific Docker CE packages. It’s advisable to install the latest stable release.
sudo dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
Explanation of the packages being installed:
docker-ce
: This is the core Docker Engine package, including the Docker daemon and client. “CE” stands for Community Edition.docker-ce-cli
: This package contains the command-line interface for Docker, which you use to interact with the Docker daemon.containerd.io
: Containerd is an industry-standard container runtime that Docker uses to manage the container lifecycle.docker-buildx-plugin
: This plugin extends the Docker CLI with BuildKit capabilities, allowing for faster and more efficient Docker image builds.docker-compose-plugin
: This plugin integrates Docker Compose functionality directly into the Docker CLI, simplifying the management of multi-container applications.
The -y
flag automatically confirms any prompts, making the installation non-interactive.
Step 4: Starting and Enabling the Docker Service
After the installation is complete, the Docker service needs to be started and configured to launch automatically on system boot.
We will use the systemctl
command to manage the Docker service.
First, start the Docker service:
sudo systemctl start docker
Next, enable the Docker service to start on boot:
sudo systemctl enable docker
To verify that Docker is running correctly, you can check its status:
sudo systemctl status docker
You should see output indicating that the service is active and running. Look for lines like Active: active (running)
. Press q
to exit the status view.
Understanding systemctl
commands:
sudo systemctl start docker
: This command initiates the Docker daemon process.sudo systemctl enable docker
: This command ensures that the Docker service is automatically started whenever the system boots up. This is crucial for persistent availability.sudo systemctl status docker
: This command provides real-time information about the Docker service, including whether it’s running, any errors, and recent logs.
Step 5: Verifying the Docker Installation
A crucial step after installation is to verify that Docker is functioning as expected. The best way to do this is by running a test container. We’ll use the hello-world
Docker image, which is specifically designed for this purpose.
Run the following command:
sudo docker run hello-world
Explanation of the command:
sudo docker run
: This command tells Docker to run a container.hello-world
: This is the name of the Docker image we are using. Docker will first check if this image is available locally. If not, it will automatically download it from Docker Hub (the default container registry).
If the installation is successful, you will see output similar to this:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
... (download progress) ...
Digest: sha256:...
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.
(assuming it was not already locally available.)
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 Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, explore:
https://docs.docker.com/get-started/
This output confirms that Docker is installed, the daemon is running, you can pull images from Docker Hub, and you can run containers.
Step 6: Adding Your User to the docker
Group
By default, you need to use sudo
to run Docker commands. This is a security measure. However, for convenience, you can add your regular user to the docker
group. This allows you to run Docker commands without sudo
.
Important Security Note: Adding a user to the docker
group grants them privileges equivalent to the root user because they can run containers that can access the host system’s file system. Only add trusted users to this group.
Execute the following command, replacing your_username
with your actual AlmaLinux username:
sudo usermod -aG docker $USER
Explanation of the command:
sudo usermod
: This command modifies user account properties with administrative privileges.-aG docker
: This option appends the user to thedocker
group.-a
(append): Ensures the user is added to the group without removing them from other groups they might already belong to.-G docker
: Specifies the group to add the user to.
$USER
: This is an environment variable that automatically resolves to the current logged-in username.
After running this command, you need to log out and log back in for the group changes to take effect. Alternatively, you can activate the changes for the current session by running:
newgrp docker
However, logging out and back in is the most reliable method to ensure all processes inherit the new group membership.
Once you’ve logged back in, you should be able to run Docker commands without sudo
:
docker run hello-world
If this command now works without requiring sudo
, your user has been successfully added to the docker
group.
Step 7: Managing the Docker Service (Common Commands)
Understanding how to manage the Docker service is essential for day-to-day operations. Here are some of the most common systemctl
commands you’ll use:
Starting the Docker Service
If Docker is stopped, you can start it using:
sudo systemctl start docker
Stopping the Docker Service
To stop the Docker daemon:
sudo systemctl stop docker
Restarting the Docker Service
To restart the Docker daemon, for example, after configuration changes:
sudo systemctl restart docker
Checking the Docker Service Status
As shown earlier, to see if Docker is running and any recent activity:
sudo systemctl status docker
Disabling Docker from Starting on Boot
If you need to prevent Docker from starting automatically when the system boots:
sudo systemctl disable docker
Enabling Docker to Start on Boot
To ensure Docker starts automatically on system boot (the default state after installation):
sudo systemctl enable docker
Step 8: Docker Image Management
Once Docker is installed, you’ll spend a lot of time working with Docker images. Images are the building blocks of containers.
Searching for Images
You can search for images on Docker Hub directly from your terminal:
docker search <image_name>
For example, to search for Nginx images:
docker search nginx
Pulling Images
To download an image from Docker Hub to your local system:
docker pull <image_name>[:tag]
The [:tag]
is optional; if omitted, it defaults to latest
. For example, to pull a specific version of Ubuntu:
docker pull ubuntu:22.04
Listing Local Images
To see all the images that are currently stored on your AlmaLinux 10 system:
docker images
This command will display the repository name, tag, image ID, creation date, and size of each image.
Removing Images
To remove an image from your local storage:
docker rmi <image_id_or_name>
You can use the image ID or the repository:tag name. For example:
docker rmi hello-world
Or using the image ID:
docker rmi a1b2c3d4e5f6
If an image is currently being used by a running container, you will not be able to remove it until the container is stopped and removed. You might need to use docker rmi -f <image_id_or_name>
to force removal, but use this with caution.
Step 9: Docker Container Management
Images are used to create containers. Containers are the running instances of an image.
Running a Container from an Image
As demonstrated with hello-world
, the docker run
command is used to create and start a container.
To run an Nginx web server in the foreground and map port 80 on your AlmaLinux host to port 80 in the container:
docker run -d -p 80:80 nginx
Explanation of options:
-d
(detached mode): Runs the container in the background, allowing you to continue using your terminal.-p 80:80
: Publishes port 80 of the container to port 80 on the host machine. The format ishost_port:container_port
.nginx
: The name of the image to use.
Listing Running Containers
To see all containers that are currently running:
docker ps
This will show you the Container ID, Image, Command, Created, Status, Ports, and Names of your running containers.
Listing All Containers (Including Stopped)
To view all containers, including those that have been stopped:
docker ps -a
Stopping a Running Container
To stop a container that is currently running:
docker stop <container_id_or_name>
For example:
docker stop nginx_container_name
Starting a Stopped Container
To start a container that has been stopped:
docker start <container_id_or_name>
Restarting a Container
To restart a container:
docker restart <container_id_or_name>
Removing a Container
To remove a container (it must be stopped first):
docker rm <container_id_or_name>
Viewing Container Logs
To view the logs generated by a container:
docker logs <container_id_or_name>
You can use the -f
flag to follow the logs in real-time:
docker logs -f <container_id_or_name>
Executing Commands Inside a Container
To execute a command within a running container, for example, to open an interactive bash shell:
docker exec -it <container_id_or_name> bash
-i
(interactive): Keep STDIN open even if not attached.-t
(tty): Allocate a pseudo-TTY.
This command will drop you into a bash prompt inside the specified container, allowing you to inspect its file system and run commands.
Step 10: Installing Docker Compose
Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services, networks, and volumes.
As of Docker Engine version 20.10, Docker Compose is included as a Docker plugin. We already installed it during the main Docker Engine installation process: docker-compose-plugin
.
You can verify its installation and version by running:
docker compose version
This command should output the installed version of Docker Compose.
If for some reason you need to install it separately (which is unlikely with recent Docker installations), you would typically download the binary and place it in your system’s PATH. However, the plugin method is preferred and cleaner.
Example of using Docker Compose:
You would typically create a docker-compose.yml
file, for example:
version: '3.8'
services:
web:
image: nginx
ports:
- "8080:80"
app:
image: python:3.9-slim
command: python -m http.server 8000
ports:
- "8000:8000"
Then, you would navigate to the directory containing this file in your terminal and run:
docker compose up -d
To stop and remove the services defined in the docker-compose.yml
file:
docker compose down
Advanced Docker Configurations and Best Practices
Now that you have Docker installed and running on AlmaLinux 10, here are some advanced configurations and best practices to consider for a more robust and efficient containerized environment.
Configuring Docker Daemon
The Docker daemon can be configured by editing the /etc/docker/daemon.json
file. This file allows you to customize various aspects of the daemon’s behavior, such as storage drivers, network settings, and logging options.
To edit this file, use your preferred text editor with sudo privileges:
sudo nano /etc/docker/daemon.json
Here’s an example of a daemon.json
file that sets up a different storage driver and configures logging:
{
"storage-driver": "overlay2",
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
},
"ip-forwarding": true
}
Key configurations:
storage-driver
: Theoverlay2
driver is generally recommended for its performance and efficiency.log-driver
: Sets the logging driver for containers.json-file
is the default.log-opts
: Configures options for the log driver, such as limiting log file size and the number of files.ip-forwarding
: Enables IP forwarding, which is often necessary for containers to communicate with the network.
After modifying daemon.json
, you must restart the Docker service for the changes to take effect:
sudo systemctl restart docker
Managing Docker Storage
Docker images, containers, and volumes consume disk space. It’s important to manage this storage effectively.
Pruning Unused Docker Objects
Docker often leaves behind unused images, stopped containers, unused networks, and build cache. The docker system prune
command helps clean these up.
To remove all stopped containers, dangling images, and unused networks:
docker system prune
For a more aggressive cleanup that also removes all unused images (not just dangling ones):
docker system prune -a
Use these commands with caution, as they will remove data that might be needed later.
Customizing Docker Data Root
By default, Docker stores its data (images, containers, volumes) in /var/lib/docker
. If you need to change this location, you can edit the Docker daemon configuration file (/etc/docker/daemon.json
) and add or modify the data-root
option:
{
"data-root": "/path/to/your/new/docker/data",
"storage-driver": "overlay2"
}
Remember to restart the Docker service after making this change. Ensure the new directory exists and has the correct permissions before restarting.
Networking in Docker
Docker provides various networking modes for containers. By default, containers are connected to a bridge network.
Inspecting Docker Networks
To view the networks Docker has created:
docker network ls
To get detailed information about a specific network:
docker network inspect <network_name_or_id>
Creating Custom Networks
Creating custom bridge networks can provide better isolation and management for your applications.
To create a new bridge network:
docker network create my_custom_network
Then, when running a container, you can attach it to this network:
docker run -d --network my_custom_network --name my_container nginx
Docker Volumes for Persistent Data
Containers are ephemeral, meaning their data is lost when the container is removed. Docker volumes are the preferred mechanism for persisting data generated by and used by Docker containers.
Creating Docker Volumes
You can create a volume explicitly:
docker volume create my_data_volume
Using Volumes with Containers
When running a container, you can mount a volume to a directory inside the container:
docker run -d -v my_data_volume:/usr/share/nginx/html nginx
This command mounts the my_data_volume
to the /usr/share/nginx/html
directory within the Nginx container. Any data written to /usr/share/nginx/html
inside the container will be stored persistently in my_data_volume
on your AlmaLinux host.
You can also use anonymous volumes (named by Docker) or bind mounts (mounting a host directory directly).
Listing Docker Volumes
To see all Docker volumes:
docker volume ls
Inspecting Docker Volumes
To get details about a specific volume:
docker volume inspect my_data_volume
Removing Docker Volumes
To remove a volume:
docker volume rm my_data_volume
Note that you cannot remove a volume that is currently in use by a container.
Conclusion
We have successfully guided you through the comprehensive process of installing Docker on AlmaLinux 10. From initial setup and repository configuration to starting the service, verifying the installation, and managing containers and images, this guide from revWhiteShadow has provided detailed, step-by-step instructions. You’ve learned how to enable Docker to start on boot, add your user for convenience, and perform essential Docker operations. Understanding Docker’s capabilities for container management, image manipulation, and data persistence with volumes is key to leveraging this powerful technology. By mastering these steps, you are now well-equipped to build, deploy, and manage containerized applications efficiently and reliably on your AlmaLinux 10 system. We encourage you to explore further with Docker Compose for orchestrating multi-container applications and to delve into Docker’s advanced networking and storage configurations to optimize your workflows. The world of containerization awaits, and your AlmaLinux 10 machine is now a robust platform for it.