Many applications – n8n, Nextcloud, Vaultwarden, your own API or an AI agent – now ship as Docker images. On an Ubuntu VPS Docker can be set up with a few commands, but besides the quick install two decisions matter: where the package comes from, and which ports are reachable from outside.
This guide uses Docker’s official apt repository, installs Compose with the docker-compose-plugin package, and shows why a container port can reach the internet despite your firewall rules.
Before you install
- Use a fresh Ubuntu LTS VPS. Docker officially supports Ubuntu 22.04, 24.04 and newer releases.
- Sign in over SSH as a user with sudo rights and check that a working firewall and backup exist.
- If you previously installed the distribution’s own docker.io or docker-compose packages, Docker’s guide says to remove them first.
Installing from the official apt repository
The official repository provides the current Docker Engine and the Compose plugin. Docker itself does not recommend piping an unknown “one-liner” install script into production.
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/ubuntu/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/ubuntu
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
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Open image full size Checking it and a first Compose file
- Check the service: sudo systemctl status docker
- Run a test: sudo docker run hello-world
- Check Compose: docker compose version
- Create a folder with a compose.yaml file, then start it: docker compose up -d
services:
web:
image: nginx:stable
restart: unless-stopped
ports:
- "127.0.0.1:8080:80"Two traps: the firewall and the docker group
- Docker handles published ports with its own network rules, so it can make a port reachable despite UFW or firewalld rules. Bind to 127.0.0.1 everything that does not need outside access, and check the publication from outside too.
- Members of the docker group effectively get root rights on the machine. Do not add anyone who does not need it; sudo is enough for daily use.
- Keep secrets (passwords, API keys) out of a compose.yaml that goes into version control; use an .env file with strict permissions.
- Back up the volumes and the Compose files; rebuilding a container does not replace a data backup.
Updating and cleaning up
Docker Engine updates through apt, while container images update separately. Back up before updating an image, then check the application log.
docker compose pull
docker compose up -d
docker compose logs --tail 50
docker image prune


