Before you start
- A 64-bit Debian 12 or 13 server or VM, or a maintained Ubuntu release
- An account with sudo (see Linux commands for beginners)
- Internet access from the server
In plain words
Docker runs an application in a container: a box holding the application and everything it needs, which runs the same way on any Linux server. Instead of installing software and its dependencies by hand, you fetch a ready-made image and start it. This guide installs Docker properly, from the official repository, with the right settings from the start. For the difference between a container and a virtual machine, see virtual machines and hypervisors.
1. Which package to install?
Several versions of Docker are around on Linux:
| Source | Package | Advice |
|---|---|---|
| Docker's official repository | docker-ce and its plugins |
Recommended: up-to-date version, Docker Compose included |
| Debian or Ubuntu repositories | docker.io |
Works, but often lags behind; don't mix it with the previous one |
| Snap (Ubuntu) | docker |
Not recommended: different behaviour (paths, permissions) |
| Docker Desktop | Graphical application | For a workstation, not for a server |
This guide follows the official method, with Docker's repository. Docker supports Debian 13 "Trixie" and Debian 12 "Bookworm", as well as the maintained Ubuntu releases.
What about Podman?
Podman is a compatible alternative, with no permanent service and designed to run without root privileges. See rootless containers with Podman and Quadlet.
2. Remove old packages
If Docker was already installed from the distribution's repositories, remove the conflicting packages. The command only touches those that are actually installed:
sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-doc podman-docker containerd runc | cut -f1)
Existing images, containers and volumes, stored in /var/lib/docker/, are kept.
3. Add the official repository
On Debian
Install the tools and the repository's signing key:
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
Declare the repository, in the .sources (deb822) format used by Debian 13:
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
The command automatically fills in the release name (trixie or bookworm) and the architecture (amd64 or arm64).
On Ubuntu
The commands are the same, replacing debian with ubuntu in both addresses, and the Suites line with:
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Check the content of the file created:
cat /etc/apt/sources.list.d/docker.sources
Types: deb
URIs: https://download.docker.com/linux/debian
Suites: trixie
Components: stable
Architectures: amd64
Signed-By: /etc/apt/keyrings/docker.asc
4. Install Docker
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
| Package | Role |
|---|---|
docker-ce |
The Docker engine (dockerd service) |
docker-ce-cli |
The docker command |
containerd.io |
The low-level container manager Docker relies on |
docker-buildx-plugin |
Building images (docker build) |
docker-compose-plugin |
Docker Compose, as docker compose (with a space) |
docker compose, no longer docker-compose
The old separate docker-compose program (with a hyphen) is discontinued. Docker Compose is now a plugin: you type docker compose up -d. Existing docker-compose.yml files remain compatible; the recommended name today is compose.yaml.
5. Check the installation
The service must be active and start with the system:
systemctl status docker
sudo systemctl enable docker.service containerd.service
Run the test container:
sudo docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
Check the versions:
docker --version
docker compose version
6. Using Docker without sudo: the docker group
By default, only root can control Docker. To avoid typing sudo for every command, you can add your account to the docker group:
sudo usermod -aG docker spo
Log out and back in (or run newgrp docker) for the change to take effect, then test:
docker run hello-world
The docker group is equivalent to root
Docker's documentation is explicit: membership of the docker group grants root-level privileges. A member of this group can start a container that mounts / and change any file on the system. Only add administration accounts to it, never an exposed service account. On a sensitive server, keep sudo, or use Docker's rootless mode, or Podman.
7. Cap the size of the logs
By default, Docker keeps without limit everything containers write to their output: a chatty container can fill the disk in a few weeks. Create the file /etc/docker/daemon.json:
{
"log-driver": "local",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}
Then restart Docker:
sudo systemctl restart docker
The local driver compresses the logs and rotates them: at most 3 files of 10 MB per container. The setting applies to containers created after the change; recreate the others (docker compose up -d --force-recreate). Logs are still read with docker logs container-name.
8. The firewall trap
Published ports bypass ufw and firewalld
When a container publishes a port (-p 8080:80 or ports: in Compose), Docker creates its own firewall rules, before those of ufw or firewalld. The result: the port can be reached from anywhere, even if ufw blocks it. This is a frequent cause of unintended exposure.
The countermeasures, from the simplest to the most complete:
| Method | Example | Effect |
|---|---|---|
| Publish on a single address | -p 127.0.0.1:8080:80 |
The service can only be reached from the server itself (ideal behind a reverse proxy) |
| Publish on the local network address | -p 192.168.1.10:8080:80 |
The service only listens on that interface |
| Don't publish at all | No ports:, containers talk over a Docker network |
Only the reverse proxy publishes ports 80 and 443 |
Filter in the DOCKER-USER chain |
Dedicated iptables or nftables rules | Fine-grained filtering, for advanced users |
| Filter upstream | Router firewall, hosting provider's security groups | Protection independent of the server |
9. Final check
| Check | Command | Expected result |
|---|---|---|
| Service enabled at boot | systemctl is-enabled docker |
enabled |
| Engine working | docker run --rm hello-world |
"Hello from Docker!" message |
| Compose available | docker compose version |
Docker Compose version v2.x or later |
| Log rotation | docker info --format '{{.LoggingDriver}}' |
local |
| Exposed ports | sudo ss -tlnp |
Only the ports you want |
10. Updating and uninstalling
Docker updates along with the rest of the system:
sudo apt update
sudo apt full-upgrade
To uninstall completely:
sudo apt purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo rm -rf /var/lib/docker /var/lib/containerd
sudo rm /etc/apt/sources.list.d/docker.sources /etc/apt/keyrings/docker.asc
Data deleted
rm -rf /var/lib/docker erases all images, containers and volumes, and therefore your applications' data. Back up the volumes first.
Key points
- Install from Docker's official repository (
docker-ce), without mixing it withdocker.io. - Docker Compose is included:
docker compose(with a space). - The docker group is equivalent to root: keep it for administrators.
- Set up log rotation in
/etc/docker/daemon.jsonright after installation. - Published ports bypass ufw: publish on
127.0.0.1behind a reverse proxy, or filter upstream.