Where to install from
| Source | What you get | When to use |
|---|---|---|
Docker’s repository, docker-ce |
a current Engine and Compose v2 from one place, plus Buildx; updates on release day | almost always — this manual covers it |
docker.io from Ubuntu |
the version as of the Ubuntu release, security fixes only; unattended-upgrades updates it — restarting containers overnight |
policy requires Docker from the main archive |
the docker snap |
sandboxed: doesn’t see every directory, has its own data paths | not for a server |
the get.docker.com script |
the same as Docker’s repository, in one command with no visible steps | throwaway machines; on your own server go step by step to see what gets added |
Setup
Remove conflicting packages
sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc docker-buildx podman-docker containerd runc | cut -f1) snap list docker 2>/dev/null && sudo snap remove dockerdpkg --get-selectionskeeps only what’s installed: on a fresh server the list is empty and there’s nothing to remove. If Docker was there, images and volumes in/var/lib/docker/surviveremove.Add Docker’s repository
sudo apt-get update sudo apt-get 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 >/dev/null <<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 sudo apt-get updateThe source is in deb822 format (
.sources), like Ubuntu’s ownubuntu.sourcessince 24.04.Signed-Bymeansaptuses this key to check Docker’s packages only, not everything.Suitescomes from/etc/os-release:nobleon 24.04,resoluteon 26.04.The commands were checked against the install page on docs.docker.com on 2026-10-18; its list of supported releases includes 26.04 and 24.04.
Install Engine and Compose
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin sudo docker version --format '{{.Server.Version}}' # 29.4.1 docker compose version # Docker Compose version v5.6.0The service starts and enables itself at boot:
systemctl is-enabled dockersaysenabled.Cap container logs
sudo tee /etc/docker/daemon.json >/dev/null <<'EOF' { "log-driver": "json-file", "log-opts": { "max-size": "10m", "max-file": "3" } } EOF sudo systemctl restart dockerEach container keeps at most three 10 MB files — 30 MB per container. Keep
json-fileas the driver rather than switching tolocal: vector and other log shippers read the*-json.logfiles (Traefik logs).The limit applies to containers created after the change. If stacks are already running, run
docker compose up -d --force-recreatein each.systemctl restart dockerrestarts every container. On a server with live sites, do it before the sites go up or at a quiet time.Decide who gets docker without sudo
The
dockergroup grants access todocker.sock, and through it root on the host:docker run -v /:/hostopens the whole file system (docker.sock). A user in thedockergroup is root without a password.How What you get sudo docker …the sudopassword stands between a stolen SSH key and rootsudo usermod -aG docker example-usershorter commands; an SSH key gives root right away rootless Docker the daemon runs as a regular user, no root needed; ports below 1024 need extra setup, and some network modes don’t work On a server where one person logs in with a passphrase-protected key, people often choose the group — the call is yours, but make it knowing the cost.
Check that it all works
sudo docker run --rm hello-world | head -2 # # Hello from Docker!
What’s next on the server
- Ports: publish only what must be visible from outside, everything else on
127.0.0.1(A host-only port goes on 127.0.0.1). ufw doesn’t close them (Docker ports bypass the input chain); a CrowdSec ban does, if the bouncer sits onforward(CrowdSec against SSH brute force). - Updates: keep Docker out of
unattended-upgrades(unattended-upgrades). Upgrade by hand:sudo apt-get install --only-upgrade docker-ce docker-ce-cli containerd.io docker-compose-plugin— and check the sites. - The proxy and the first service — Traefik from scratch (Traefik from scratch).
If it doesn’t work
permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock
- Cause
- The user isn’t in the
dockergroup, or was added but the session is old. - Fix
sudo docker …, orusermod -aG docker example-userand a fresh login — but first read what that group grants (step 5).
docker-ce : Conflicts: docker.io during install
- Cause
- Docker from Ubuntu’s repository is already on the server.
- Fix
- Step 1: remove
docker.ioand its neighbours. Images and volumes in/var/lib/dockersurviveremove.
Docker from snap: docker compose can’t see files in /opt or /srv
- Cause
- Snaps run sandboxed: Docker from snap sees files only in the home directory, and external disks only after
snap connect docker:removable-media. The Ubuntu Server installer offers it in its list of snaps. - Fix
sudo snap remove dockerand install from Docker’s repository. Snap data lives in/var/snap/docker/— move the volumes before removing it.
/var/lib/docker/containers/*/*-json.log files filled the disk
- Cause
- The
json-filedriver has no limit by default. A limit indaemon.jsonapplies only to containers created after it was set. - Fix
- Step 4, then recreate the containers:
docker compose up -d --force-recreatein every stack.
docker: 'compose' is not a docker command
- Cause
- The
docker-compose-pluginisn’t installed; the olddocker-compose(v1, with a hyphen) hasn’t been updated in years. - Fix
sudo apt install docker-compose-plugin.
A container port is open from outside though ufw doesn’t allow it
- Cause
- Docker publishes ports with rules that bypass ufw (Docker ports bypass the input chain).
- Fix
ports: - "127.0.0.1:8080:8080"(A host-only port goes on 127.0.0.1), or noports:at all — go through Traefik.
How to check
Docker comes from the right repository:
apt-cache policy docker-ce | sed -n '1,4p'
# docker-ce:
# Installed: 5:29.4.1-1~ubuntu.24.04~noble
# Candidate: 5:29.4.1-1~ubuntu.24.04~noble
# Version table:
The log limit applies to a new container:
sudo docker run -d --name logtest alpine sh -c 'while true; do date; sleep 1; done'
sudo docker inspect logtest --format '{{.HostConfig.LogConfig}}'
# {json-file map[max-file:3 max-size:10m]}
sudo docker rm -f logtest
Ports open to the outside — check each one from a phone:
sudo docker ps --format '{{.Names}}\t{{.Ports}}' | grep '0.0.0.0'