01
The right VPS for Docker
Docker relies on Linux kernel features to isolate its containers. On a full virtual machine (KVM) or a dedicated server, which have their own kernel, it installs with no special settings. In a container VPS (LXC), containers have to be nested: this only works if the host has enabled nesting. The guide KVM or LXC VPS explains why.
On our Ryzen and Intel VPS, which are LXC containers, nesting is enabled: Docker and Docker Compose install there with the official script below, with no extra settings.
On the system side, a recent Debian or Ubuntu is the simplest choice: they are the best documented distributions for Docker. Plan memory accordingly too: each container uses as much as the application it holds, database included.
02
Installing Docker and Docker Compose
Install Docker from Docker's official repository rather than from the distribution package, which is often older. The official script does it in one go:
sudo apt update && sudo apt install -y ca-certificates curl
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
It installs the Docker engine and the Docker Compose plugin, used with the docker compose command (two words). Then check:
sudo docker run --rm hello-world
docker compose version
In a container VPS, also check that sudo docker info shows Storage Driver: overlay2: this is the normal mode, fast and light on disk space.
Adding your user to the docker group (sudo usermod -aG docker $USER) saves typing sudo for every command. Be aware that this group in practice grants root rights on the machine: only give it to trusted accounts.
03
A first service with Docker Compose
Rather than long docker run commands, describe each service in a compose.yaml file, kept in its own folder:
services:
web:
image: nginx:stable
restart: unless-stopped
ports:
- "127.0.0.1:8080:80"
volumes:
- ./site:/usr/share/nginx/html:ro
docker compose up -d starts the service in the background, docker compose logs -f shows its logs, docker compose down stops it. The file becomes the documentation of your setup: keep it, with its neighbours, in a Git repository.
04
Trap no. 1: published ports bypass the firewall
This is the most common surprise. When a container publishes a port ("8080:80"), Docker writes its own filtering rules, before UFW's: the port is open to the whole world even if UFW blocks it.
- publish on
127.0.0.1 (as in the example above) anything that should only be reached from the VPS itself;
- expose your sites through a single reverse proxy (Nginx, Caddy, Traefik) on ports 80 and 443, which also handles HTTPS certificates;
- never publish a database port on the public address.
05
Trap no. 2: logs filling the disk
By default, Docker keeps all the logs of each container, with no size limit. A chatty service ends up filling the disk. Limit them once and for all in /etc/docker/daemon.json:
{
"log-driver": "json-file",
"log-opts": { "max-size": "10m", "max-file": "3" }
}
Restart Docker (sudo systemctl restart docker): the limit applies to containers created afterwards. And from time to time, docker system prune removes images and containers that are no longer used.
06
Trap no. 3: forgetting volumes in backups
A container is recreated in one command; its data is not. Volumes and mounted folders (databases, files uploaded by users) are what you need to back up, off the VPS.
- for a database, make a clean export (
pg_dump, mysqldump) rather than copying its files while it runs;
- to update a service:
docker compose pull then docker compose up -d, after a backup, and pinning the versions of important images rather than latest.
07
Docker on a CloudFive VPS
The Ryzen VPS and the Intel VPS accept Docker and Docker Compose: they are unprivileged LXC containers with nesting enabled. The Ryzen VPS, on Ryzen 9 9950X, DDR5 and NVMe, is the fastest per core; the Intel VPS gives more cores for less. Both share the host machine's kernel: if your project needs to touch the kernel itself (a specific module, a custom kernel), choose a dedicated server, with its own kernel. In any case, also follow the guide securing a Linux VPS.
08
Frequently asked questions
Can Docker be installed on any VPS?
On a full virtual machine (KVM), yes. In an LXC container VPS, only if the host has enabled nesting. On our Ryzen and Intel VPS, that is the case: Docker and Docker Compose install with the official script.
Is Docker Compose installed with Docker?
With Docker's official script, yes: Docker Compose is installed as a plugin and used with the docker compose command, two words.
Why is my Docker port open despite UFW?
Docker writes its own filtering rules before UFW's. Publish internal ports on 127.0.0.1 and expose your sites through a reverse proxy on ports 80 and 443.
What should be backed up on a Docker VPS?
Volumes and mounted folders, which hold the data, as well as the compose.yaml files. For a database, a clean export is better than a copy of its files.