Installing Docker on Debian isn’t complicated. The real pitfall is doing it too quickly, with an outdated package. docker.io, an incorrectly declared repository or a server whose firewall has not been reviewed.
In my case, I always prefer to check the basics before starting the installation: Debian version, architecture, conflicting packages, Docker service, user group, and test. hello-worldThis prevents you from having a partially functioning installation, or worse, a container that exposes a port when you thought you were still protected by UFW.
First check the Debian version
Docker Engine is documented for Debian 13, Debian 12, and Debian 11. Before copying a command you find somewhere, first clearly identify the machine. This is especially important if you are administering an older server, a cloned VM, or a derivative distribution.
cat /etc/os-release
cat /etc/debian_version
uname -m
dpkg --print-architecture
The Docker repository uses the codename Debian, for example bookworm Or trixie. If VERSION_CODENAME is empty, or if you are on a derivative distribution, do not proceed randomly. Manually replace the codename with the one from the Debian base actually being used.
If you have any doubts about this, also reread the LinuxEnCaja guide on the Reliable commands to check the Debian versionThis is exactly the kind of control that prevents inconsistent APT deposits.
Remove any old packages that might be causing problems.
On Debian, the package docker.io It may exist in the distribution’s repositories. It does not follow the same installation cycle as official Docker packages. If your goal is to install Docker Engine from the official repository, first remove any potentially conflicting packages.
sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-doc podman-docker containerd runc | cut -f1)
This command might simply return that nothing is installed. That’s not a problem. However, it doesn’t remove your old containers, images, volumes, and networks stored under /var/lib/dockerDo not touch this folder without a backup if the machine has already been used.
Add the official Docker repository properly
The clean method involves a dedicated APT source file and a key in /etc/apt/keyringsI advise you to avoid old tutorials that add a key with apt-keyThis is no longer the right method.
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
Next, add the Docker repository with the Debian codename detected by the system:
sudo tee /etc/apt/sources.list.d/docker.sources <
The simple check after this step:
apt-cache policy docker-ce
grep -R "download.docker.com" /etc/apt/sources.list.d/
You should see the Docker repository in the sources and a candidate docker-ceIf APT doesn't see anything, don't force the installation. First, fix the file docker.sources, the code name or network connectivity.
Install Docker, then control the service
The basic installation includes Docker Engine, the client, containerd, Buildx, and the Compose plugin. This is the expected package for a clean Debian installation today.
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Don't stop at the APT completion message. Verify that the service has started correctly:
sudo systemctl status docker --no-pager
systemctl is-active docker
sudo journalctl -u docker -b --no-pager | size -n 40
If the service fails to start, begin by checking the logs. They are often more informative than repeated restarts. To review the active services and failed units, see the article on systemctl and the list of Linux services This check is complete.
Test with hello-world, but don't trivialize the docker group
The official test remains simple:
sudo docker run hello-world
If the image downloads, runs, and displays its confirmation message, the Docker engine is working. You can also check the installed versions:
docker --version
docker compose version
sudo docker info
The temptation then is to add your user to the group docker to avoid sudoIt's convenient, but not without risk: a user belonging to this group can gain very high privileges via the Docker daemon. On a test machine, why not? On a shared server, I would only do it for a clearly identified admin account.
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
Docker Run Hello World
If you launched Docker with sudo Before switching to the group, you might also encounter a permissions issue in ~/.dockerIn this case, correct the owner rather than running all the commands randomly:
sudo chown -R "$USER":"$USER" ~/.docker
chmod -R go-rwx ~/.docker
Review the firewall settings before exposing a container.
This is the point I would really check before putting Docker on a server accessible from the internet. Docker manipulates network rules, and the ports published by containers can bypass what you think you've blocked with UFW or firewalld.
sudo ss -ltnp
sudo docker ps
sudo docker ps --format "table {{.Names}} {{.Ports}}"
sudo ufw status numbered
If you are publishing a service, reread the command. -p 127.0.0.1:8080:80 does not have the same impact as -p 8080:80The first limits listening to the local machine, the second exposes the port on available interfaces.
For an exposed Debian server, I advise you to also reread the UFW rules to set before opening a serverDocker and the firewall must be considered together, not separately.
The checks I perform before validating
Before considering the installation complete, I perform this short series of checks. It's brief, but it catches most faulty installations:
cat /etc/os-releaseconfirms the correct Debian base.apt-cache policy docker-cepoints to the expected Docker repository.sudo systemctl status docker --no-pagerno error is reported.sudo docker run hello-worldworks at least once.docker compose versionanswer if you plan to use Compose.sudo ss -ltnpdoes not show any port published unexpectedly.
To go further, keep the Docker documentation for Debian, THE Linux post-installation steps and the page of Debian versions maintainedAnd if Docker refuses to start, don't immediately perform a complete reinstallation: start by journalctl -u docker -bThat's often where the real mistake lies.