Installing Docker on Debian 12 and 13
Updated: 18 November 2026 · Guide · VPS · Linux
The cleanest way to install Docker on Debian is from Docker's official apt repository: store the GPG key, add the package source, install five packages. According to its own guide Docker supports Debian 13 (Trixie) and Debian 12 (Bookworm). Compose comes along as a plugin and is then called docker compose, with a space.
This assumes a Debian server with a sudo user and a configured firewall. If that's still missing, do the basic setup first (link below). All commands here come from the official Docker documentation.
Removing old or unofficial packages
Debian ships its own packages such as docker.io that conflict with the official ones. This command removes them if present. If apt reports that none of them are installed, that's fine. Images, containers and volumes under /var/lib/docker are left in place.
sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-doc docker-buildx podman-docker containerd runc | cut -f1)
Setting up Docker's package source
First store Docker's signing key, then add the package source in the new deb822 format. The codename (bookworm or trixie) and the architecture are read from the system automatically; you don't need to adjust anything.
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
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
Installing Docker Engine and Compose
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Debian starts the service by itself after installation. Whether everything works is shown by a test container that prints a confirmation and exits again:
sudo systemctl status docker sudo docker run hello-world docker compose version
On our test bench exactly this route via the official Docker repository worked on a fresh Debian 13 machine: hello-world started, and the Compose plugin was present.
Docker without sudo: what the docker group means
After installation the docker group has no members, so every Docker command needs sudo. If you don't want that, add your user to the group. Important to know: according to the Docker documentation the docker group grants root-level privileges. Anyone allowed to operate Docker can take over the whole server with it. So only add users you would also give root.
sudo usermod -aG docker $USER newgrp docker docker run hello-world
The trap: published ports bypass ufw
This is the point where most fresh Docker servers are unintentionally left open. If you start a container with -p 8080:80 or ports: in Compose, the port is published by default on all of the host's addresses (0.0.0.0 and ::). Docker redirects this traffic via NAT before ufw's rules take effect. The Docker documentation says so explicitly: Docker and ufw are incompatible in this respect, and ufw rules don't apply to published container ports. ufw status doesn't show the port as open, but it is.
The simplest fix: bind ports that are only needed on the server itself to 127.0.0.1. Then only the host can reach them, and a web server in front (nginx as a reverse proxy) passes requests on in a controlled way. On the command line it looks like this:
docker run -d -p 127.0.0.1:8080:80 nginx:stable
ss shows whether it worked: if it says 127.0.0.1:8080, the port is closed from outside. If it says 0.0.0.0:8080 or *:8080, it's open to everyone, whatever ufw says.
sudo ss -tlpn | grep 8080
According to Docker, your own filter rules for containers belong in the DOCKER-USER chain, created with iptables or ip6tables. Docker supports iptables-nft and iptables-legacy for this. Rulesets created directly with nft are not supported by Docker on the same system. For most cases binding to 127.0.0.1 is the simpler and safe route.
With a VPS from us there's also the firewall in the VPS panel. It acts on the host in front of your machine, so Docker in the guest can't bypass it. It's still no substitute for proper binding in the guest: whatever is open in the panel is open for the container too.
A short Compose example
Compose describes containers in a file instead of long command lines. Create a directory and in it a compose.yaml with this content:
services:
web:
image: nginx:stable
restart: unless-stopped
ports:
- "127.0.0.1:8080:80"docker compose up -d docker compose ps docker compose logs -f
Put the port specification in quotes, as the Compose reference recommends, so YAML doesn't misread it as a number. Without a host address Docker binds to all interfaces, and the Compose reference itself warns that this can bypass firewall rules. restart: unless-stopped restarts the container after a crash or a server reboot, unless you explicitly stopped it.
Updates and uninstalling
Docker updates come via the normal apt upgrade, because the packages come from the repository. Docker advises against using the convenience install script for updates. To remove it completely, purge the packages and then delete /var/lib/docker and /var/lib/containerd. That also removes all images, containers and volumes, so back up what you want to keep first.
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
- First: set up SSH and firewallsudo user, SSH key, ufw
- Next: nginx as a reverse proxyMake containers on 127.0.0.1 reachable via HTTPS
- Reach internal services via VPNWireGuard instead of open ports
- See VPS plansAll tiers with real figures
- Configure your own VPSChoose memory for your containers freely