Prerequisites
A freshly deployed Ubuntu 24.04 VPS and root SSH access (or sudo). Make sure the system is up to date:
apt update && apt upgrade -yStep 1 — Install dependencies
apt install -y ca-certificates curl gnupg
install -m 0755 -d /etc/apt/keyringsStep 2 — Add the official Docker repository
Never use Ubuntu's docker.io package, often outdated. The official repository guarantees the latest stable versions:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
| gpg --dearmor -o /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" \
> /etc/apt/sources.list.d/docker.list
apt updateStep 3 — Install Docker Engine and Compose
apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
docker --version
docker compose versionStep 4 — Configure the daemon for production
Create /etc/docker/daemon.json:
{
"log-driver": "json-file",
"log-opts": { "max-size": "10m", "max-file": "3" },
"live-restore": true,
"storage-driver": "overlay2"
}Capped logs prevent filling the disk; live-restore keeps your containers running during daemon updates. Restart: systemctl restart docker.
Step 5 — Verify with a test container
docker run --rm hello-world
docker run -d --name web -p 80:80 nginx:alpine
curl -I localhostBasic security
Never expose the Docker socket over TCP without TLS. If you use UFW, remember Docker inserts its own iptables rules — ports published with -p bypass UFW by default. To lock down, expose on localhost (-p 127.0.0.1:8080:80) and go through a reverse proxy.
Going further
Install Watchtower for automatic image updates, or read our article "Docker in production on a VPS" for memory limits and monitoring.