Blog / Tutorials

How to Install Docker on AlmaLinux, CentOS, Rocky Linux & Fedora: The Complete Server Guide

(Updated: )
7 min read
How to Install Docker on AlmaLinux, CentOS, Rocky Linux & Fedora: The Complete Server Guide

Docker revolutionized server deployments by enabling applications to be isolated into lightweight, portable, self-contained units called containers. No matter what your underlying operating system is, a Docker container spins up exactly the same way.

However, many default repositories (like those built into RHEL, AlmaLinux, CentOS, and Rocky Linux) often point to Podman instead of Docker, or they host severely outdated versions of the Docker Engine. To guarantee you have access to the latest security features and the integrated docker-compose-plugin, you need to pull it directly from Docker's official source.

Step 1: Remove Old Versions

Before you install the official engine, you need to verify no older, conflicting packages are lingering on the system (even if you never installed them yourself). These packages usually orbit the names docker or docker-engine.

Run this command to clear the slate smoothly:

Running sudo dnf remove docker to clean up any old conflicting Docker packages on AlmaLinux or Rocky Linux before a fresh install

sudo dnf remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

It is perfectly fine if dnf reports that none of these packages are installed.

Step 2: Set up the Docker Repository

You need to tell your package manager (dnf) exactly where to find the official Docker releases. Docker provides a convenient configuration tool natively supported by RHEL systems via the yum-utils package.

Install the utilities:

Running sudo dnf install -y yum-utils on AlmaLinux to install the yum-config-manager tool needed to add the Docker CE repository

sudo dnf install -y yum-utils

Now, use the yum-config-manager to safely add the official Docker repository to your system sources:

Running sudo yum-config-manager --add-repo to add the official Docker CE repository to AlmaLinux or Rocky Linux

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

(Even if you are on AlmaLinux, Rocky Linux, or Fedora, passing the /centos/ path is correct, as they share the absolute exact same binary architecture for Enterprise Linux).

Step 3: Install Docker Engine

With the repository securely added, your system knows where to look. You can now install the entire Docker suite.

This command installs the core engine (docker-ce), the command-line interface (docker-ce-cli), the container runtime (containerd.io), and modern plugins like Docker Compose V2 (docker-compose-plugin).

Running sudo dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin on AlmaLinux to install Docker Engine and Compose

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

Step 4: Start and Enable Docker

Unlike Ubuntu, which automatically starts services immediately after downloading them, RHEL-family distributions prefer you to intentionally start them.

You need to start the Docker daemon and enable it so it safely wakes up every time the server reboots. You can do both in one single systemctl command:

Running sudo systemctl enable --now docker on AlmaLinux to start the Docker service and enable it to launch automatically on boot

sudo systemctl enable --now docker

To confirm the service is alive, check the status:

Running sudo systemctl status docker on AlmaLinux to confirm the Docker daemon is active and running correctly

sudo systemctl status docker

Look for the bright green "active (running)" text.

Step 5: Verify the Installation

To prove unequivocally that Docker can successfully pull images from the internet and spin them up into operating containers, use the standard test payload:

Running sudo docker run hello-world on AlmaLinux or Rocky Linux to verify Docker Engine is installed and working correctly

sudo docker run hello-world

If your configuration is correct, a container will be downloaded, run its code, and output a large confirmation block beginning with:

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

Docker and your Firewall: Docker manages its own network rules directly through iptables. While RedHat systems use firewalld, which is generally more integrated with Docker than UFW, it's still best practice to be careful when exposing ports via the -p or --publish flag. Always verify your open ports with sudo firewall-cmd --list-all.

Step 6 (Optional): Run Docker Without Sudo

You probably noticed you had to type sudo to run the test script. By default, the Docker daemon binds to a Unix socket instead of a TCP port, and that socket is owned by the root user.

If you created your own user account (as outlined in our User Management Guide), typing sudo hundreds of times a day can be tedious. You can grant your user native Docker rights by adding them to the docker group.

sudo usermod -aG docker $USER

Warning: The docker group grants privileges that are functionally equivalent to root access. Only add heavily trusted users to this group.

To force the system to acknowledge your new group standing without having to log out entirely:

su - $USER

Now, re-run the test without the sudo prefix:

docker run hello-world

If it works, congratulations! Your VPS is fully equipped to deploy the infinite number of pre-packaged container apps available on Docker Hub natively and securely.

For a reliable environment supporting rapid project prototyping with Docker, checkout our high-performance line of affordable Budget VPS environments today.

Frequently Asked Questions

Older packages (like docker or docker-engine) conflict with the official docker-ce (Community Edition) package, which is maintained by Docker. Removing them prevents dependency resolution issues.
The docker-ce-cli is the command-line interface tool used to interact with the Docker daemon. Keeping the CLI package separate allows you to manage remote Docker daemons from a local machine without installing the engine itself.
You can add your user to the docker group by running sudo usermod -aG docker $USER. You will need to log out and log back in for this change to take effect.
You can check the status of the Docker service by running the systemctl command: sudo systemctl status docker.
Podman is a daemonless container engine developed by Red Hat as an alternative to Docker. While podman is the default on standard RHEL installations, Docker is still widely preferred due to its mature ecosystem and native Docker Compose plugin support.

Suggest Edits on GitHub

Spot a typo or want to improve this guide? This post is open-source and open for community contributions.

Edit this post
Back to all posts

Languages