Operating System CentOS

How to Install Docker on CentOS Stream 9 and 10 (and What to Do About CentOS 7)

Install Docker Engine and the Compose plugin from the official repository on CentOS Stream 9 or 10, and see your options if a server is still on CentOS 7.

Docker packages an application together with everything it needs to run into a container, so the same image behaves the same way on your laptop and on your server. This guide installs Docker Engine from Docker's own repository on CentOS Stream 9 and CentOS Stream 10, which are the CentOS releases Docker supports today.

If you are still on CentOS 7

CentOS 7 reached end of life on 30 June 2024. It no longer receives security updates, and Docker's installation guide for CentOS now lists only CentOS Stream 9 and CentOS Stream 10. Running new container workloads on CentOS 7 means running them on an unpatched system.

The practical route is to create a new server on a supported release and move your containers to it: images come from your registry, and data lives in volumes that you can copy across. CentOS Stream, AlmaLinux and Rocky Linux are the usual successors.

Requirements

  • A server running CentOS Stream 9 or CentOS Stream 10.
  • A user with sudo rights.
  • The centos-extras repository enabled. It is enabled by default; if you turned it off, turn it back on.

Step 1: Remove old Docker packages

Older packages from the distribution can conflict with the official ones. Remove them first:

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

dnf may report that none of these packages are installed. That is fine. Images, containers and volumes stored in /var/lib/docker are not deleted by this command.

Step 2: Add the Docker repository

sudo dnf -y install dnf-plugins-core
sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Step 3: Install Docker Engine

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

When dnf asks you to accept the GPG key, compare the fingerprint it shows with the one published in Docker's installation guide for CentOS before you answer yes.

This installs the engine, the command-line client, the container runtime, and the Buildx and Compose plugins. A docker group is created, but no users are added to it.

Step 4: Start Docker

Installing the packages does not start the service. Start it now and have it start on every boot:

sudo systemctl enable --now docker

Step 5: Test the installation

sudo docker run hello-world

Docker downloads a small test image, runs it, and prints a confirmation message. If you see that message, the engine works.

Check the versions of the engine and the Compose plugin:

docker --version
docker compose version

Run Docker without sudo (optional)

To run docker as your own user, add that user to the docker group, then log out and back in:

sudo usermod -aG docker $USER

Be aware of what this grants. Anyone in the docker group can start a container that mounts the host's file system, which is equivalent to root access. Add only accounts you would trust with sudo.

AlmaLinux and Rocky Linux

Docker's documentation covers CentOS Stream and Red Hat Enterprise Linux, and does not mention AlmaLinux or Rocky Linux. Because both are built to be compatible with RHEL, administrators commonly use the CentOS repository shown above on them. It works in practice, but it is not a combination Docker lists as supported, so test updates before you apply them to production servers.

Update or remove Docker

Docker updates arrive with your normal system updates:

sudo dnf upgrade

To remove the packages:

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

Your images, containers and volumes stay on disk. To delete them as well, which cannot be undone:

sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

Frequently asked questions

How much memory does Docker need?

The engine itself is light. What matters is what your containers need. A server with 1 GB of RAM can run a few small services; databases and build jobs need more.

Do I need to install Docker Compose separately?

No. The docker-compose-plugin package installed in step 3 provides the docker compose command (with a space). The older standalone docker-compose binary is not needed.

Can I use Podman instead?

CentOS Stream ships Podman in its own repositories, and it runs most Docker images with the same command syntax. If you only need to run containers and do not depend on the Docker daemon or its API, it is a reasonable alternative.

Share story:

Continue reading other guides on How VPS.