Install Docker on Ubuntu 22.04 VPS (2026 guide)
A clean install of Docker Engine and the Compose plugin from Docker's official APT repository — plus the four post-install steps that decide whether you have a usable Docker host or a sharp pile of permission errors.
Don't use apt install docker.io
Ubuntu's docker.io package is months behind upstream Docker, doesn't include the modern Compose plugin (only the legacy docker-compose Python binary), and packages an older version of containerd that occasionally interacts badly with cgroups v2. Use Docker's official APT repo instead. Five extra lines, much better outcome.
Prerequisites
- Ubuntu 22.04 LTS or 24.04 LTS, freshly installed.
- A non-root user with sudo (see initial Ubuntu setup).
- An SSH connection in.
Tested on Ubuntu 22.04 LTS on a 2 GB Inferno VPS, Docker CE 27.3.
Step 1 — Remove any conflicting packages
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do
sudo apt remove -y $pkg
done
On a fresh server this is a no-op. On a server that already had docker.io, this avoids version conflicts.
Step 2 — Add Docker's GPG key and repo
sudo apt update
sudo apt 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
Step 3 — Install Docker Engine and plugins
sudo apt update
sudo apt install -y \
docker-ce \
docker-ce-cli \
containerd.io \
docker-buildx-plugin \
docker-compose-plugin
Verify the install:
docker --version
docker compose version
sudo docker run --rm hello-world
If hello-world exits cleanly, Docker is working at the system level.
Step 4 — Post-install: add your user to the docker group
sudo usermod -aG docker $USER
newgrp docker
docker run --rm hello-world # no sudo this time
Security note: the docker group is effectively root. Any user in it can mount the host filesystem into a container and escape. Add only trusted users.
Step 5 — Post-install: enable Docker on boot
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
On Ubuntu these are usually enabled by default after install — confirm with systemctl is-enabled docker.
Step 6 — Post-install: log rotation
Docker's default JSON log driver never rotates. On a busy host this fills the disk. Set sane global limits in /etc/docker/daemon.json:
sudo nano /etc/docker/daemon.json
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
},
"live-restore": true
}
Reload:
sudo systemctl restart docker
live-restore: true keeps your containers running across docker daemon restarts — useful during minor upgrades.
Step 7 — Post-install: firewall + Docker
Docker manipulates iptables directly. If you also use UFW, you'll discover that ufw deny rules are silently bypassed by Docker's DOCKER-USER chain. Two paths:
- Recommended: bind your container ports to
127.0.0.1in the Compose file (e.g."127.0.0.1:5678:5678") and put Nginx in front. UFW then only needs to allow 80/443. - Alternative: edit
/etc/ufw/after.rulesto add rules to theDOCKER-USERchain. Doable; finicky.
For real-world setups the first approach is simpler and what we recommend across the site.
Verifying everything
docker info | grep -E "Server Version|Storage Driver|Cgroup|Logging Driver"
# Server Version: 27.3.x
# Storage Driver: overlay2
# Cgroup Driver: systemd
# Logging Driver: json-file
docker compose version
# Docker Compose version v2.30.x
If Cgroup Driver says cgroupfs instead of systemd, you can switch — but the default on Ubuntu 22.04+ is already systemd, so you should not need to.
Common install issues
"Got permission denied while trying to connect to the Docker daemon"
You forgot the usermod -aG docker $USER step, or you didn't open a new shell after running it. Either log out and back in, or run newgrp docker in the current shell.
"Could not get lock /var/lib/dpkg/lock-frontend"
Unattended-upgrades is running. Wait a few minutes, or check with sudo lsof /var/lib/dpkg/lock-frontend.
"GPG error: NO_PUBKEY"
The GPG key step failed silently. Re-run curl ... | sudo gpg --dearmor -o ... and confirm /etc/apt/keyrings/docker.gpg exists.
Containers can't reach the internet
Almost always conflicting iptables management — fail2ban or your firewall flushing Docker's chains. Restart Docker (sudo systemctl restart docker) and confirm sudo iptables -L DOCKER-USER shows expected rules.
Need a fresh VPS for this install?
Any of Inferno's plans from $3.49/mo handle Docker fine. NVMe and 10 Gbps come on every tier, which matters when you stack multiple containers.
What to do next
- Production patterns for docker-compose.yml — healthchecks, secrets, limits, log rotation.
- Hardening Docker on a public VPS — cap drops, rootless mode, image scanning.
- Traefik reverse proxy or Caddy reverse proxy for auto-discovery and TLS.
- Portainer if you want a UI on top.
Author: Daniel Ferro — self-hosting writer, Lisbon. Last tested: 2026-05-22 on Ubuntu 22.04 LTS, Docker CE 27.3, Inferno VPS 2 GB (Helsinki).