How to Install Docker on Linux: Ubuntu, Debian, Fedora, RHEL and Arch

How to Install Docker on Linux: Ubuntu, Debian, Fedora, RHEL and Arch

Reading time1 min
#docker#linux#ubuntu#debian#devops

How to Install Docker on Linux: Ubuntu, Debian, Fedora, RHEL and Arch

On a Linux server, "installing Docker" means installing Docker Engine: the dockerd daemon, the docker CLI, containerd, and the Buildx and Compose plugins. Docker Desktop also runs on Linux, but servers and most workstations only need Engine.

Pick an install method

  • Docker's own apt or dnf repository. The recommended way. You get current releases, Compose v2 (docker compose) and Buildx, and upgrades through the normal package manager.
  • Distro packages (docker.io on Ubuntu and Debian). Maintained by the distro, usually older, Compose packaged separately. Fine if you prefer distro packages, but do not mix them with Docker's packages.
  • The convenience script at get.docker.com. Sets up the same official repository in one command. Good for test VMs and CI, not recommended by Docker for production.
  • Snap (snap install docker). Confined, uses different paths and often lags behind. Avoid unless you specifically want a snap.

Ubuntu

Docker currently supports Ubuntu 22.04, 24.04 and 26.04 LTS. First remove any conflicting packages. This does not delete existing images or volumes in /var/lib/docker.

sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc docker-buildx podman-docker containerd runc | cut -f1)

Add Docker's signing key and repository:

sudo apt update
sudo apt install -y ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF

Signed-By scopes the key to this one repository instead of trusting it for every source, which is why the old apt-key add instructions are gone. The UBUNTU_CODENAME fallback makes the same snippet work on derivatives such as Linux Mint.

Install and test:

sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo docker run --rm hello-world

On Debian and Ubuntu the package enables and starts the service for you.

Debian

The steps are the same as for Ubuntu (Debian 12 and 13 are supported). Use debian in the key URL (https://download.docker.com/linux/debian/gpg) and in the repository file:

sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/debian
Suites: $(. /etc/os-release && echo "$VERSION_CODENAME")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF

Fedora

Fedora 41 and later ship dnf5, which changed the config-manager syntax, so older --add-repo instructions fail there.

sudo dnf remove docker docker-client docker-client-latest docker-common docker-latest \
  docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine
sudo dnf config-manager addrepo --from-repofile https://download.docker.com/linux/fedora/docker-ce.repo
sudo dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl enable --now docker

When dnf asks to import the key, check that the fingerprint is 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35.

RHEL and CentOS Stream

RHEL 8, 9 and 10 are supported. Use dnf (on these releases yum is only an alias for it). The remove step also takes out Podman, which RHEL installs by default, because its packages conflict with Docker's.

sudo dnf remove docker docker-client docker-client-latest docker-common docker-latest \
  docker-latest-logrotate docker-logrotate docker-engine podman runc
sudo dnf -y install dnf-plugins-core
sudo dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo
sudo dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl enable --now docker

For CentOS Stream 9 and 10, use https://download.docker.com/linux/centos/docker-ce.repo instead. CentOS 7 reached end of life in 2024, so guides written for it are out of date. Rocky Linux and AlmaLinux are not on Docker's official list. The CentOS repository usually works there, but test it first.

On Amazon Linux 2023, Docker comes from Amazon's own repository: sudo dnf install -y docker, then sudo systemctl enable --now docker.

Arch Linux

sudo pacman -S docker docker-compose docker-buildx
sudo systemctl enable --now docker.service

The one-command install

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh --dry-run   # print the steps without running them
sudo sh ./get-docker.sh

The script detects the distribution, adds Docker's official repository and installs the latest stable release. It always installs the newest version, including major upgrades, and it is not meant to be re-run on a host that already has Docker. After the first run, update with apt or dnf like any other package.

After installing

Run docker without sudo.

sudo usermod -aG docker $USER
newgrp docker          # or log out and back in
docker run --rm hello-world

Membership in the docker group is equivalent to root on that host. On a shared machine, consider rootless mode, which runs the daemon as an ordinary user (see Docker's rootless documentation for the extra packages it needs).

Start on boot. Debian and Ubuntu do this automatically. On the RHEL family and Fedora, systemctl enable --now docker above already took care of it.

Limit log growth. The default json-file driver keeps logs forever. Set a default in /etc/docker/daemon.json:

{
  "log-driver": "local"
}

The local driver rotates by default. If you need json-file (some log shippers read it), use "log-opts": {"max-size": "10m", "max-file": "3"} instead. Run sudo systemctl restart docker afterwards. The setting applies only to containers created after the change.

Mind the firewall. Ports published with -p bypass UFW and firewalld rules, because Docker writes its own iptables rules. If a service should only be reachable locally or through a reverse proxy, publish it as -p 127.0.0.1:8080:80, or add rules to the DOCKER-USER chain.

Updating and uninstalling

Updates come with the normal system upgrade (sudo apt upgrade or sudo dnf upgrade). To pin a version, list the available versions with apt list --all-versions docker-ce or dnf list docker-ce --showduplicates and install that exact version.

To remove Docker completely, including all images, containers and volumes:

sudo apt purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
sudo rm -rf /var/lib/docker /var/lib/containerd

Troubleshooting

  • permission denied while trying to connect to the Docker daemon socket: your user is not in the docker group yet, or you have not started a new login session.
  • Cannot connect to the Docker daemon: the service is not running. Check sudo systemctl status docker and sudo journalctl -u docker.
  • apt reports Conflicting values set for option Signed-By: an old docker.list from a previous guide is still in /etc/apt/sources.list.d/ next to docker.sources. Delete the duplicate.
  • docker-compose: command not found: Compose v2 is a plugin, so the command is docker compose with a space.

Quick reference

# Ubuntu / Debian: add the repo (see above), then
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Fedora
sudo dnf config-manager addrepo --from-repofile https://download.docker.com/linux/fedora/docker-ce.repo

# RHEL / CentOS Stream
sudo dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo
sudo dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl enable --now docker

# Arch
sudo pacman -S docker docker-compose docker-buildx

# Any distro, test machines only
curl -fsSL https://get.docker.com | sudo sh

# Everywhere
sudo usermod -aG docker $USER
docker run --rm hello-world