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

How to Install Docker on AlmaLinux 10: A Comprehensive Installation Guide by Tech Today

Welcome to Tech Today’s definitive guide on installing Docker on AlmaLinux 10. For users of Enterprise Linux systems seeking a robust and reliable container runtime, the process of setting up Docker is paramount. AlmaLinux, a community-driven, open-source Linux distribution, stands as a strong alternative for those who value stability and long-term support, making it an excellent platform for deploying containerized applications. This article will walk you through the entire installation process, from preparing your system to verifying your Docker installation, ensuring you have a fully functional Docker environment ready for your containerization needs. We understand that precise steps and comprehensive details are crucial for a successful installation, and we are here to provide just that, empowering you to leverage the full potential of Docker on your AlmaLinux 10 server.

Understanding Docker and its Importance on AlmaLinux

Before diving into the installation steps, it’s essential to grasp why Docker is so vital, especially within an Enterprise Linux environment like AlmaLinux. Docker is an open-source platform that automates the deployment, scaling, and management of applications inside containers. Containers package an application and its dependencies together in a standardized unit for software development. This means your application will run consistently, regardless of the environment it’s deployed in.

For AlmaLinux users, particularly those coming from or migrating from other Enterprise Linux distributions, Docker offers a consistent way to manage application lifecycles. It simplifies dependency management, isolates applications from the underlying operating system, and drastically reduces the “it works on my machine” problem. AlmaLinux’s commitment to stability and long-term support makes it an ideal foundation for production workloads, and Docker amplifies this by providing a predictable and isolated execution environment for your applications. Whether you’re running web servers, databases, development tools, or complex microservices, Docker on AlmaLinux 10 ensures that your applications are portable, scalable, and easily manageable.

Preparing Your AlmaLinux 10 System for Docker Installation

A successful Docker installation begins with a well-prepared system. This section outlines the necessary preliminary steps to ensure a smooth and error-free setup on your AlmaLinux 10 instance.

Updating Your AlmaLinux 10 System

The first and most critical step is to ensure that your AlmaLinux 10 system is up to date. This guarantees that you have the latest package repositories, security patches, and kernel updates, which are often prerequisites for newer software like Docker.

To update your system, open a terminal and execute the following commands:

sudo dnf update -y

This command will refresh your package lists and upgrade all installed packages to their latest available versions. The -y flag automatically confirms any prompts during the update process. After the update is complete, it is a good practice to reboot your system to ensure all changes take effect, especially kernel updates.

sudo reboot

Uninstalling Previous Docker Versions (if applicable)

If you have previously attempted to install Docker or have older versions of containerization tools like Podman or LXC installed, it is advisable to remove them to avoid conflicts. Docker Engine, Docker CLI, and related packages can sometimes install alongside other container runtimes.

To remove any pre-existing Docker installations, 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 \
                  lxc

This comprehensive command targets a wide range of potential Docker-related packages and related container tools to ensure a clean slate.

Setting Up Required Dependencies for Docker

While the Docker installation process typically handles most dependencies, it’s good practice to ensure certain core utilities are present. These utilities are usually part of the standard AlmaLinux installation but are worth mentioning for completeness.

Specifically, you might need packages for managing repositories and downloading software. The dnf-plugins-core package provides essential plugins for DNF, including the ability to manage repositories.

To install it, if it’s not already present, run:

sudo dnf install dnf-plugins-core -y

This step is crucial for adding new software repositories that will host the official Docker packages.

Adding the Official Docker Repository to AlmaLinux 10

AlmaLinux 10, by default, might not include the latest Docker packages in its standard repositories. To get the most up-to-date and well-supported version of Docker Engine, we need to add the official Docker CE (Community Edition) repository.

Creating the Docker Repository File

The process involves creating a new .repo file in the /etc/yum.repos.d/ directory. This file will contain the configuration details for the Docker repository.

Execute the following command to create and populate the repository file:

sudo tee /etc/yum.repos.d/docker-ce.repo <<EOF
[docker-ce]
name=Docker CE -- latest
baseurl=https://download.docker.com/linux/centos/8/\$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
EOF

Let’s break down this command:

After creating this file, your system will know where to find the official Docker packages.

Importing the Docker GPG Key

To ensure the integrity and authenticity of the Docker packages you download, you must import the Docker GPG key. This key is used by dnf to verify that the packages have not been tampered with.

Run the following command to import the GPG key:

sudo rpm --import https://download.docker.com/linux/centos/gpg

This command downloads the GPG key from the specified URL and imports it into your system’s RPM database.

Updating the DNF Cache

After adding the new repository and importing the GPG key, it’s essential to update the DNF package manager’s cache. This allows dnf to recognize the new repository and list the available Docker packages.

Execute the following command:

sudo dnf makecache

This command refreshes the metadata for all enabled repositories, including the newly added Docker CE repository.

Installing Docker Engine on AlmaLinux 10

With the repository correctly configured and the cache updated, we can now proceed with installing Docker Engine and its associated components.

Installing Docker CE

To install the latest stable version of Docker Engine, Docker CLI, and Docker Compose, use the dnf install command.

Run the following command in your terminal:

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

Let’s break down this command:

This command will download and install all the necessary Docker components from the official Docker CE repository.

Verifying the Docker Installation

Once the installation is complete, it’s crucial to verify that Docker has been installed correctly and is functioning as expected.

Starting the Docker Service

The Docker daemon needs to be running for Docker commands to work. You can start the Docker service using systemctl.

sudo systemctl start docker

Enabling Docker to Start on Boot

To ensure Docker starts automatically every time your system boots up, enable the Docker service:

sudo systemctl enable docker

This command creates the necessary symbolic links for systemd to manage the Docker service at startup.

Checking Docker Service Status

You can check the status of the Docker service to confirm it is running without errors:

sudo systemctl status docker

You should see output indicating that the service is active (running). Press q to exit the status view.

Running the Hello-World Container

The ultimate test of a successful Docker installation is to run a simple test container. Docker provides a hello-world image specifically for this purpose.

Execute the following command:

sudo docker run hello-world

If your Docker installation is successful, this command will perform the following actions:

  1. It connects to the Docker daemon.
  2. It pulls the hello-world image from Docker Hub (Docker’s public registry).
  3. It creates a new container from that image.
  4. The container runs and prints a “Hello from Docker!” message.
  5. The container exits.

You should see output similar to this:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2cf29dc70850: Pull complete
Digest: sha256:8739420b10333c0789551f93727a147c2316e9455170805b4e23419356399e37
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.
   (it was already local)
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, visit:
 https://docs.docker.com/get-started/

This output confirms that Docker is installed, running, and capable of pulling images and running containers.

Post-Installation Steps and Best Practices

After a successful installation, there are a few additional steps and practices that are highly recommended for an optimal Docker experience on AlmaLinux 10.

Managing Docker as a Non-Root User

By default, you need to use sudo to run Docker commands. This is a security measure, as the Docker daemon runs with root privileges. However, it can be cumbersome to type sudo for every Docker command. You can configure Docker to allow specific users to run commands without sudo by adding them to the docker group.

First, create the docker group if it doesn’t already exist:

sudo groupadd docker

Next, add your current user to the docker group:

sudo usermod -aG docker $USER

After running this command, you will need to log out and log back in for the group changes to take effect. Alternatively, you can use the newgrp command to apply the group changes immediately in your current terminal session:

newgrp docker

Now, you should be able to run Docker commands without sudo.

Understanding Docker Images and Containers

It’s worth briefly touching upon the core concepts of Docker: images and containers.

You can list available images on your system using:

docker images

And list running containers using:

docker ps

To see all containers, including stopped ones, use:

docker ps -a

Configuring Docker Daemon Settings (Optional)

The Docker daemon’s configuration file is located at /etc/docker/daemon.json. You can use this file to customize various daemon settings, such as the default logging driver, storage driver, or network configuration.

For example, to change the default logging driver to json-file and set a maximum log file size:

{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}

To apply these changes, you would need to restart the Docker daemon:

sudo systemctl restart docker

Caution: Modifying daemon.json incorrectly can prevent the Docker daemon from starting. Always back up the file before making changes.

Leveraging Docker Compose

For applications that consist of multiple services (e.g., a web application with a database), Docker Compose is an invaluable tool. It allows you to define and manage multi-container applications using a YAML file (docker-compose.yml).

With the docker-compose-plugin installed, you can now use the docker compose command. For example, to start services defined in a docker-compose.yml file in the current directory:

docker compose up -d

The -d flag runs the containers in detached mode (in the background).

To stop these services:

docker compose down

Security Considerations for Docker on AlmaLinux

Running containers introduces its own set of security considerations. Here are a few key points to keep in mind:

Troubleshooting Common Docker Installation Issues on AlmaLinux 10

While we aim for a seamless installation, occasional issues can arise. Here are some common problems and their solutions.

“Cannot connect to the Docker daemon. Is the docker daemon running on this host?”

This is perhaps the most common error. It means the Docker service is not running or is not accessible.

Solution:

  1. Ensure the Docker service is started:
    sudo systemctl start docker
    
  2. Check the status of the Docker service for any errors:
    sudo systemctl status docker
    
  3. If the service fails to start, check the Docker daemon logs for clues:
    sudo journalctl -u docker.service
    

Docker Commands Not Found

If you run a docker command and get “command not found,” it indicates that the Docker CLI is not in your system’s PATH or the installation failed.

Solution:

  1. Verify the Docker installation was successful.
  2. Ensure your user is part of the docker group and has logged out and back in or used newgrp docker.
  3. Check if the Docker binary exists, usually at /usr/bin/docker.

Repository Configuration Errors

Problems with the .repo file or GPG key import can lead to DNF errors.

Solution:

  1. Double-check the content of /etc/yum.repos.d/docker-ce.repo for any typos or incorrect URLs.
  2. Ensure the GPG key was imported correctly using sudo rpm --import https://download.docker.com/linux/centos/gpg.
  3. Refresh the DNF cache: sudo dnf makecache.

“no matching manifest for linux/amd64 in the manifest list entries” or Similar Image Pull Errors

This error can occur if the Docker repository URL is incorrect for your architecture or AlmaLinux version, or if there’s a temporary issue with Docker Hub.

Solution:

  1. Confirm that the baseurl in /etc/yum.repos.d/docker-ce.repo is correct for AlmaLinux 10 (which is based on RHEL 8). The provided URL using centos/8 should generally work, but verify it aligns with Docker’s current repository structure for RHEL 8 derivatives.
  2. Ensure your AlmaLinux 10 installation is properly registered and can access external repositories.

Conclusion

We have successfully guided you through the comprehensive process of installing Docker on AlmaLinux 10. By following these detailed steps, from preparing your system and configuring the official Docker repository to installing Docker Engine and verifying its functionality with the hello-world container, you are now equipped with a robust containerization platform. We’ve also covered essential post-installation configurations, such as managing Docker as a non-root user, and highlighted key security best practices to ensure a safe and efficient Docker environment.

AlmaLinux 10 provides a stable and reliable base for running containerized applications, and Docker enhances this by offering unparalleled portability, scalability, and ease of management. Whether you are deploying web applications, microservices, or development environments, Docker on AlmaLinux 10 is a powerful combination. Remember to keep your Docker installation updated and to follow security best practices to maintain a secure and performant system.

At Tech Today, we are committed to providing you with the most accurate and up-to-date technical guidance. We trust this detailed guide will empower you to confidently utilize Docker on your AlmaLinux 10 systems. For further exploration into advanced Docker features, container orchestration with Kubernetes, or other enterprise Linux topics, continue to explore the resources available at Tech Today. Your journey into efficient and modern application deployment starts here.