Home Rocky LinuxHow to Install Docker on Rocky Linux 9

How to Install Docker on Rocky Linux 9

by Knowledge Base Linux
Install Docker on Rocky Linux 9 with stacked containers

Docker does not ship in the Rocky Linux repositories, so the correct way to install Docker on Rocky Linux 9 is to use Docker’s official CE repository — the same one used for CentOS and RHEL clones. This guide walks through adding the repository, resolving the well-known conflict with Podman, enabling the daemon, and running your first containers with the Compose plugin.

Prerequisites to Install Docker on Rocky Linux 9

  • A Rocky Linux 9 server with sudo access and a current system: sudo dnf upgrade -y.
  • Awareness that Rocky ships Podman by default. Podman is a fine container tool, but if your team, CI pipelines or documentation are built around the Docker CLI and Compose, Docker CE is the right choice.

Step 1: Add the Official Docker Repository – How to Install Docker on Rocky

Docker publishes packages for RHEL-family systems through the CentOS repository path, which works unchanged on Rocky Linux 9:

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

You should see docker-ce-stable in the list. Using the official repository matters: you get timely security fixes straight from Docker instead of an outdated third-party build.

Step 2: Install Docker Engine and the Compose Plugin – How to Install Docker on Rocky

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

If DNF reports conflicts with podman, buildah or runc, allow it to replace them:

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

The conflict is expected: Docker’s containerd and Podman’s stack both want to own the container runtime layer. On a dedicated Docker host, removing the Podman packages is the clean solution.

Deploying a container when you install Docker on Rocky Linux 9

Step 3: Start Docker and Grant Your User Access

sudo systemctl enable --now docker
sudo usermod -aG docker $USER
docker --version
docker compose version

Log out and back in so the group change takes effect, then run the test image:

docker run --rm hello-world

The “Hello from Docker!” message confirms the client, daemon, networking and image pulling all work. Compare this flow with our Ubuntu tutorial on how to install Docker on Ubuntu 22.04 — the package steps differ, the concepts are identical.

Step 4: Run Something Useful — and Mind SELinux

Start a throwaway Nginx container:

docker run -d --name web -p 8080:80 nginx:alpine
curl http://localhost:8080

Remember to open the port in firewalld if external access is needed: sudo firewall-cmd --permanent --add-port=8080/tcp && sudo firewall-cmd --reload. Our guide to configure firewalld on Rocky Linux 9 explains the details — and note that Docker also manages iptables rules itself, so prefer publishing ports with -p instead of hand-writing forwarding rules.

When you bind-mount host directories into containers on Rocky, SELinux will block access unless you label the mount. Add the :Z suffix:

docker run -d -v /srv/site:/usr/share/nginx/html:Z nginx:alpine

The :Z flag relabels the content so only this container can use it. Our SELinux Rocky Linux 9 guide explains why this works.

Step 5: A Quick Compose Test

Create a minimal compose.yaml:

services:
  web:
    image: nginx:alpine
    ports:
      - "8081:80"
docker compose up -d
docker compose ps
docker compose down

Troubleshooting

  • “Cannot connect to the Docker daemon”: the service is not running, or your shell session predates the group change. Check systemctl status docker and log in again.
  • Permission denied on /var/run/docker.sock: your user is not in the docker group — remember that group membership is effectively root-equivalent, so grant it carefully.
  • Containers cannot reach the internet: check that IP forwarding survived any custom firewall work: sysctl net.ipv4.ip_forward should be 1, which Docker sets automatically.
  • Installation conflicts return after an update: a Rocky update reinstalled Podman components. Re-run the install command with --allowerasing.

Step 6: Restart Policies, Storage Hygiene and Log Limits

Three habits keep a Docker host healthy over time. First, give important containers a restart policy so they return after a reboot or crash:

docker run -d --restart unless-stopped --name web -p 8080:80 nginx:alpine
docker update --restart unless-stopped existing-container

Second, prune regularly. Images and stopped containers quietly eat disk:

docker system df
docker system prune

Third, cap container log sizes before a runaway container fills the disk. Create /etc/docker/daemon.json:

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

Restart the daemon with sudo systemctl restart docker to apply it. Pair this with the disk checks from our guide on how to check disk space on Linux and your Docker host will stay boring — in the best possible way.

Conclusion

You now have a working Docker host: you can install Docker on Rocky Linux 9 from the official repository, run containers and use Compose, with SELinux volume labels handled correctly. For updates and repository hygiene, keep the official Docker documentation for CentOS/RHEL-family systems bookmarked, and review the DNF repositories guide for general package management on Rocky.

Finally, remember that containers complement rather than replace the rest of this Rocky Linux series: the host still needs the firewall, SELinux awareness and update routine described in the companion guides. A well-kept host plus disposable containers is precisely the combination that makes Docker on Rocky Linux such a comfortable platform for long-running services.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.