Skip to content

How to Install Docker on Ubuntu VPS

  • A fresh Ubuntu 24.04 LTS VPS and a user with sudo access.
  • SSH access, a backup or snapshot, and enough available disk space.
  • Kernel support for namespaces, cgroups and overlay filesystems. Check with your provider: some VPS virtualization configurations cannot run Docker even with root access.
Terminal window
sudo apt update
sudo apt upgrade -y
uname -r

If a kernel update is installed, schedule a reboot before continuing. Do not perform an unplanned reboot on a production server.

2. Install Docker from the official repository

Section titled “2. Install Docker from the official repository”

Remove conflicting distribution packages only if you are not using them for existing workloads.

Terminal window
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 >/dev/null <<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 -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

If APT reports conflicts with docker.io, containerd, or runc, follow the official conflict-removal instructions after checking which containers already run on this server.

Terminal window
sudo systemctl enable --now docker
sudo docker version
sudo docker compose version
sudo docker run --rm hello-world

The last command should print Docker’s hello-world confirmation. Errors about permissions, cgroups or mount operations can indicate kernel/virtualization restrictions; ask your VPS provider to verify container support.

Create a test-only web service bound to localhost, rather than exposing it publicly:

Terminal window
mkdir -p ~/docker-demo && cd ~/docker-demo
cat > compose.yaml <<'EOF'
services:
web:
image: nginx:stable-alpine
restart: unless-stopped
ports:
- "127.0.0.1:8080:80"
EOF
sudo docker compose up -d
curl -I http://127.0.0.1:8080
sudo docker compose logs --tail=20

When you are finished: sudo docker compose down.

  • Keep Docker and the host OS updated; check docker compose ps regularly.
  • Avoid adding all users to the docker group: Docker access is effectively root access.
  • Do not expose the Docker API (2375) to the internet.
  • Only publish ports needed by the application. Docker-published ports can bypass some host firewall rules; audit them separately.
  • Back up named volumes and the Compose configuration. A running container is not a backup.
Problem Check
Cannot connect to Docker daemon sudo systemctl status docker
operation not permitted VPS kernel/cgroup/container restrictions
Port already in use sudo ss -ltnp
Container exits sudo docker compose logs

Official reference: Docker Engine on Ubuntu.


Need a VPS for this project? Compare ProstoHosting VPS plans.