Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

What You Need

  • A 64-bit Debian release that Docker supports: Debian 12 (bookworm) and Debian 13 (trixie).
  • A user with sudo rights: a minimal Debian install may not have sudo. Install it as root with apt install sudo and add your user to the sudo group, as shown in how to add a user to a group.
  • A KVM-based VPS or a dedicated server: Docker needs kernel features that container-based virtual servers may not offer.

Debian's own archive has a package called docker.io. It is maintained by Debian and often older than Docker's release. This guide installs Docker's packages, the method Docker documents for servers, and the same one used in how to install Docker on Ubuntu.

Step 1: Remove Conflicting Packages

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

On a fresh server none of these are installed, and apt says so. Images and volumes in /var/lib/docker are not removed by this step.

Step 2: Add Docker's Repository

First the signing key, stored in /etc/apt/keyrings:

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

Then the repository entry, which names your release automatically:

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

sudo apt update

Check that apt update lists download.docker.com without errors. A key error usually means the key file is missing or not readable.

Step 3: Install Docker Engine

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

This installs the engine, the command-line client, the container runtime, and the Buildx and Compose plugins. On Debian the service starts by itself and is enabled at boot. Check it, and if it is not running, start it with sudo systemctl start docker:

sudo systemctl status docker
docker --version
docker compose version

More on service states is in how to list services with systemctl.

Step 4: Run a Test Container

sudo docker run hello-world

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

Step 5: Run Docker Without sudo (Optional)

Read this first: membership in the docker group equals root on the host. Anyone in the group can start a container that mounts the whole file system and change any file on it. Add only accounts you would trust with root.

sudo usermod -aG docker $USER
newgrp docker
docker run hello-world

Log out and back in to make the change permanent in every session.

Docker and Your Firewall

A port you publish with -p is opened by Docker's own rules and bypasses the rules you set with ufw or firewalld. A database started with -p 3306:3306 is reachable from the internet. To keep a service on the server, bind it to the loopback address:

docker run -d -p 127.0.0.1:8080:80 nginx

Docker works with iptables-nft or iptables-legacy. Rules written directly with nft are not supported on a Docker host; custom filtering for container traffic belongs in the DOCKER-USER chain, written with iptables, as Docker's documentation describes.

Updates and Next Steps

Docker now updates with the rest of Debian through sudo apt update and sudo apt upgrade. Containers are not touched by that; to move them to newer images, see how to update a Docker container. To start several containers from one file, continue with docker compose up -d.

Was this answer helpful?
Loading...