Install Docker on a Linux VPS (2026)
This guide shows how to install Docker on a VPS running Debian 13 or Ubuntu 24.04, with Docker Engine and Docker Compose from the official Docker repository. It also covers the Docker post-install steps, how Docker behaves with the firewall and how to maintain your containers.
You need root access or a sudo user. First secure access with the guide Set up an SSH key on a Linux VPS and set up the firewall with How to set up the UFW firewall on Ubuntu or Debian.
Add the official Docker repository
Do not install the docker.io package from the Debian or Ubuntu repositories. It lags behind the official releases. The Docker repository provides docker-ce, the version maintained by Docker. The commands follow the official documentation.
On Debian 13
sudo apt update
sudo apt install -y ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/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/debian
Suites: $(. /etc/os-release && echo "$VERSION_CODENAME")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF
sudo apt update
On Ubuntu 24.04
sudo apt update
sudo apt install -y 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
Install Docker Engine and Docker Compose
sudo apt install -y docker-ce docker-ce-cli containerd.io \
docker-buildx-plugin docker-compose-plugin
This command installs five packages.
docker-ce, the Docker engine.docker-ce-cli, thedockercommand.containerd.io, the container runtime.docker-buildx-plugin, to build images for several architectures.docker-compose-plugin, Docker Compose v2.
Check the installed versions.
docker --version
docker compose version
Docker Compose v2 runs as
docker compose, two words. The olddocker-composebinary, with a hyphen, is v1, retired in July 2023 according to the Docker documentation. Yourcompose.ymlordocker-compose.ymlfiles remain compatible.
Enable Docker at VPS startup, then check its status.
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
sudo systemctl status docker
For a container to come back after a reboot too, give it a restart policy, such as restart: unless-stopped in the Compose file.
Use Docker without sudo
By default, Docker commands require sudo. Add your user to the docker group. The second command applies the change to the current session without logging out.
sudo usermod -aG docker $USER
newgrp docker
These steps follow Docker's Linux post-installation steps page.
The
dockergroup grants rights equivalent to root. A group member can mount the whole VPS disk inside a container. Only grant it to accounts that need it, as explained on the Docker daemon attack surface page.
Docker can also run entirely without root, in rootless mode. Setting it up takes longer but reduces the attack surface. In any case, never share the /var/run/docker.sock socket with an untrusted container, and never expose the Docker API over TCP without mutual TLS.
Run a first container
docker run hello-world
Docker downloads the image from Docker Hub, starts a container, prints a message and stops. The line Hello from Docker! confirms that everything works.
Docker and the firewall
Docker writes its own filtering rules. A port published with -p or ports: is open on the VPS public IP, even if UFW refuses it. For a service behind a reverse proxy such as Nginx, publish the port on the local address.
# docker run command
docker run -p 127.0.0.1:8080:80 nginx
# In a compose.yml
ports:
- "127.0.0.1:8080:80"
Port 8080 can then only be reached from the VPS itself. Never expose database ports (3306, 5432, 6379) directly. For a port that must stay public, the guide How to set up the UFW firewall on Ubuntu or Debian explains how to filter containers with ufw-docker. The Docker documentation describes this behaviour.
Maintain Docker and your containers
Clean up
Docker piles up images, stopped containers and unused networks.
# Remove stopped containers, unused images and orphan networks
docker system prune
# Also include unused volumes (permanent deletion)
docker system prune --volumes
The
--volumesoption erases the data of volumes not attached to any container. Check them before you run it.
Read a container's logs
# Show the container's logs
docker logs my-app
# Follow them live
docker logs -f my-app
# Show only the last lines
docker logs --tail 100 my-app
Update Docker and images
Docker Engine updates along with the other packages.
sudo apt update
sudo apt upgrade docker-ce docker-ce-cli containerd.io \
docker-buildx-plugin docker-compose-plugin
For an image, download the new version, then recreate the container. With Compose, the last two commands do both.
# Download the latest version of an image
docker pull image:tag
# With Compose, download then recreate the containers
docker compose pull
docker compose up -d
To deploy and maintain a full stack, follow the guide Docker Compose on a Linux VPS. Before going to production, also review Secure a Linux VPS.
Need help?
Open a ticket from Tickets › Open a Ticket, or from the Contact support tile at the bottom of the VPS page. In the Related Service field, pick the VPS so the team saves time. You can also ask your question on the OuiHeberg Discord.
Root access, your choice of distribution and management from the OuiHeberg client area.
View plans →