Docker runs apps in containers: isolated environments that bring exactly the software an app needs. In this guide you install Docker Engine with the Compose plugin on a Debian or Ubuntu VPS, using the method from the Docker documentation: Docker's own apt repository. Updates then simply come in through apt.
No server yet? You can rent a VPS with Debian or Ubuntu from us, from €3 a month.
Log in as your user with sudo, as in Secure your new Linux VPS. Did you install Docker packages from Debian or Ubuntu before, such as docker.io? Then remove them first, as the Docker documentation describes: they conflict with Docker's own packages.
Add Docker's repository
This block works on Debian and Ubuntu: $ID fills in debian or ubuntu by itself.
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/$(. /etc/os-release && echo "$ID")/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 <<EOF
Types: deb
URIs: https://download.docker.com/linux/$(. /etc/os-release && echo "$ID")
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 update
In November 2026 Docker supports Debian 12 and 13 and Ubuntu 22.04, 24.04, 26.04 and 26.10.
Install and test Docker
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo docker run hello-world
The test container prints Hello from Docker! and then stops. On Debian and Ubuntu, Docker also starts by itself when your VPS boots. Compose is a plugin: you type docker compose, with a space.
Docker Compose and restart policies
With Compose you describe your containers in a file. Create a folder, for example ~/web, with a file compose.yaml in it:
services:
web:
image: nginx:alpine
restart: unless-stopped
ports:
- "8080:80"
In that folder, sudo docker compose up -d starts the container in the background. sudo docker compose ps shows the status, sudo docker compose logs the output, and sudo docker compose down stops and removes the container. At http://203.0.113.10:8080 you now see the Nginx welcome page.
The restart line decides when Docker starts a container again:
no: never. This is the default.on-failure: only after an error, not when Docker itself restarts, for example after a reboot of your VPS.always: always. A container you stopped yourself comes back as soon as Docker restarts.unless-stopped: likealways, but a container you stopped yourself stays off.
With docker run you give the same choice with --restart unless-stopped.
Watch out: Docker ports bypass ufw
The example opens port 8080 to the whole internet, even if ufw doesn't allow that port. Docker forwards traffic to containers before ufw applies its rules. So ufw status doesn't show what is really reachable.
- Only publish ports that have to be public. Containers in the same Compose file reach each other by their service name, so a database doesn't need
portsat all. - Is there a web server on the VPS itself in front of the container, such as Nginx from Host a website on your VPS with Nginx and SSL? Then publish on localhost only, with
"127.0.0.1:8080:80".
Without sudo: the docker group
sudo usermod -aG docker $USER
Log out and in again, and docker works without sudo. But be aware: the docker group is as powerful as root. Anyone in it, and every script you start, can run a container that reads and changes every file on your VPS. So only add people you would also give root, or just keep typing sudo. Docker's rootless mode isolates more strictly.
Background on ports and firewalls is in Packet filtering and firewalls.