How to Install Docker on Ubuntu VPS
Requirements
Section titled “Requirements”- A fresh Ubuntu 24.04 LTS VPS and a user with
sudoaccess. - 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.
1. Update the operating system
Section titled “1. Update the operating system”sudo apt updatesudo apt upgrade -yuname -rIf 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.
sudo apt install -y ca-certificates curlsudo install -m 0755 -d /etc/apt/keyringssudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.ascsudo chmod a+r /etc/apt/keyrings/docker.ascsudo tee /etc/apt/sources.list.d/docker.sources >/dev/null <<EOFTypes: debURIs: https://download.docker.com/linux/ubuntuSuites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")Components: stableArchitectures: $(dpkg --print-architecture)Signed-By: /etc/apt/keyrings/docker.ascEOFsudo apt updatesudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginIf APT reports conflicts with docker.io, containerd, or runc, follow the official conflict-removal instructions after checking which containers already run on this server.
3. Check that Docker works
Section titled “3. Check that Docker works”sudo systemctl enable --now dockersudo docker versionsudo docker compose versionsudo docker run --rm hello-worldThe 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.
4. Start your first Compose service
Section titled “4. Start your first Compose service”Create a test-only web service bound to localhost, rather than exposing it publicly:
mkdir -p ~/docker-demo && cd ~/docker-democat > compose.yaml <<'EOF'services: web: image: nginx:stable-alpine restart: unless-stopped ports: - "127.0.0.1:8080:80"EOFsudo docker compose up -dcurl -I http://127.0.0.1:8080sudo docker compose logs --tail=20When you are finished: sudo docker compose down.
5. Security and operations
Section titled “5. Security and operations”- Keep Docker and the host OS updated; check
docker compose psregularly. - Avoid adding all users to the
dockergroup: 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.
Troubleshooting
Section titled “Troubleshooting”| 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.