Many programs are published as Docker images: you start them with one command, and they bring everything they need with them. AlmaLinux and Rocky Linux do not ship Docker itself; their own container tool is Podman. This page installs Docker and Docker Compose from Docker's own package source and starts a first container. The commands were tested with Docker 29 on a dedicated server with AlmaLinux 9 and in a test machine with Rocky Linux 9; run them as root.


1. Install Docker

dnf install dnf-plugins-core
dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo
dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl enable --now docker

The second line adds Docker's package source. During the first installation from it, dnf asks whether to import its signing key. Answer y if it shows the fingerprint 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35 from https://download.docker.com/linux/rhel/gpg. Docker does not start by itself after the installation; the last line starts it now and after every restart. Test it:

docker run --rm hello-world

The answer starts with Hello from Docker!. Updates of Docker then come with your normal updates (dnf upgrade).

To use Docker as your normal user without sudo, add the user to the docker group, then log out and in again:

usermod -aG docker alex
⚠ The docker group is like root

Whoever can use Docker can control the whole server. Add only users you would also give the root password to.

2. Start a Container

This starts the web server nginx and makes it reachable on port 8080 of your server. --restart unless-stopped starts it again after a restart of the server.

docker run -d --name web -p 8080:80 --restart unless-stopped nginx
docker psList running containers and their ports
docker logs webShow what the container writes
docker stop web / docker start webStop and start it
docker rm -f webStop and delete the container (the image stays)
Docker ports ignore firewalld

A port published with -p 8080:80 is reachable from the whole internet, even when firewalld is on and has no rule for it. The page on port 8080 answers from another server although firewall-cmd --list-ports is empty. If only programs on the server itself need the port, publish it on 127.0.0.1; then it cannot be reached from outside:

docker run -d --name web -p 127.0.0.1:8080:80 --restart unless-stopped nginx

3. Docker Compose

With Compose you describe your containers in a file and start them all with one command. Create a folder and in it the file compose.yaml:

mkdir -p ~/web && cd ~/web
nano compose.yaml
services:
  web:
    image: nginx
    ports:
      - "127.0.0.1:8080:80"
    restart: unless-stopped

Run these commands in the same folder; after docker compose up -d the page answers on 127.0.0.1:8080:

docker compose up -dStart everything in the background
docker compose psShow the state
docker compose pull && docker compose up -dUpdate to the newest images
docker compose downStop and remove the containers

Good to Know

  • Portainer, a web interface for your containers, is installed with the same commands as on Ubuntu: Docker on Your Linux Server, step 4. Open its port with firewalld only if you need it from outside; publishing it on 127.0.0.1 and using an SSH tunnel is safer.
  • Podman (dnf install podman) runs most Docker images with the same commands, podman run … instead of docker run …. Its published ports also bypass firewalld: Podman adds its container network to the firewalld zone trusted, and a published port 8080 answers from outside.
  • Docker keeps images, containers and volumes in /var/lib/docker. docker system df shows how much space they take; see also What Fills the Disk and What Loads the Server.

Related Guides

View all AlmaLinux and Rocky Linux guides

Was this answer helpful? 0 Users Found This Useful (0 Votes)