The docker.io package in Ubuntu’s universe repository is usually a release or two behind, ships without Compose v2 as a plugin, and gives you a daemon configured for desktop convenience rather than server reliability. For a host that will run real workloads, install Docker Engine from Docker’s own apt repository, pin the channel, and tune the daemon before any container starts.
How to verify
Check what — if anything — is already installed and which repository is on the host:
docker --version 2>/dev/null || echo "no docker"
apt list --installed 2>/dev/null | grep -E "docker|containerd"
ls /etc/apt/sources.list.d/ | grep docker
cat /etc/apt/keyrings/docker.gpg 2>/dev/null | file -
systemctl is-enabled docker 2>/dev/null
If docker.io is the package source, you are on the distro build. The Docker-CE build comes from docker-ce and docker-ce-cli. Mixing the two breaks upgrades — pick one and stay on it.
What’s happening
Docker Engine on Linux is three pieces: containerd (the OCI runtime that actually starts containers), dockerd (the API daemon you talk to), and the docker CLI. The official repo ships all three together, plus the Compose v2 plugin and BuildKit plugin, on a versioned cadence that matches upstream releases. The distro package is built by Ubuntu maintainers from a snapshot — fine for dev, awkward in production because security backports lag and Compose v1 (Python) is end-of-life.
GPG verification matters because the apt repository is signed; without the keyring in place, apt update will refuse to fetch from the Docker URL. The daemon’s defaults — json-file log driver with no rotation, no live-restore, no userland proxy disabled — are the next thing to fix.
The procedure
- Remove any conflicting packages first. This is the most common cause of a botched install:
for pkg in docker.io docker-doc docker-compose docker-compose-v2 \
podman-docker containerd runc; do
sudo apt-get remove -y $pkg
done
- Set up Docker’s apt repository with a keyring file (the
apt-key addflow is deprecated):
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
- Install the engine, CLI, containerd, BuildKit plugin, and Compose plugin in one shot:
sudo apt-get install -y docker-ce docker-ce-cli containerd.io \
docker-buildx-plugin docker-compose-plugin
- Before starting workloads, configure
/etc/docker/daemon.json. The defaults will bite you in production:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
},
"live-restore": true,
"userland-proxy": false,
"no-new-privileges": true,
"default-ulimits": {
"nofile": {
"Name": "nofile",
"Soft": 65536,
"Hard": 65536
}
}
}
live-restore keeps containers running across daemon restarts (critical for kernel upgrade flows). Log rotation prevents a chatty container from filling /var/lib/docker. userland-proxy: false shaves a process per published port.
- Restart and verify:
sudo systemctl restart docker
sudo systemctl enable docker
sudo docker run --rm hello-world
docker info | grep -E "Logging Driver|Live Restore|Userland Proxy"
- Add operators to the
dockergroup so they don’t need sudo for every command — but understand the security implication: membership indockeris effectively root on the host.
sudo usermod -aG docker $USER
newgrp docker
For production hosts where root-equivalent access via the daemon is unacceptable, run rootless Docker or move to Podman. See Docker user namespaces for the namespace-remapping middle ground.
Common pitfalls
- Forgetting
apt-mark hold docker-ceif you want to pin a version — unattended upgrades will otherwise pull in minor releases. - Installing on a host where
iptables-nftandiptables-legacyare both present; Docker may pick the wrong one and your published ports will silently not work. - Leaving the default
bridgenetwork MTU at 1500 on a host with VPN/overlay interfaces (typical MTU 1450) — TCP retransmits everywhere. Set"mtu": 1450indaemon.jsonif relevant. - Skipping
live-restoreand discovering during the first kernel upgrade that every container dies onsystemctl restart docker. - Adding a user to the
dockergroup on a host where that user should not have root.
Stack Harbor runs this install pattern (and the daemon tuning behind it) as part of managed operations on every client host that ships container workloads.