Skip to content

How to install Docker and Docker Compose on a VPS

Install Docker Engine from the official repository, run your first container and an app with Docker Compose.

Updated: 2026-11-07 · 1 min read

Docker runs applications in containers with the same environment on your laptop and on the server. For Docker we recommend plan S or larger (2 vCPU, 4 GB RAM).

Install on Ubuntu and Debian

The official script installs Docker Engine and the Compose plugin from Docker's repository:

curl -fsSL https://get.docker.com | sh
systemctl enable --now docker
docker --version
docker compose version

If you're not working as root, add your user to the docker group and log in again:

usermod -aG docker deploy

Install on AlmaLinux and Rocky Linux

dnf -y install dnf-plugins-core
dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo
dnf -y install docker-ce docker-ce-cli containerd.io docker-compose-plugin
systemctl enable --now docker

Your first container

docker run --rm hello-world

An app with Docker Compose

Create a project folder and a compose.yaml file:

services:
  web:
    image: nginx:stable
    ports:
      - "80:80"
    restart: unless-stopped
  db:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: change-me
    volumes:
      - pgdata:/var/lib/postgresql/data
    restart: unless-stopped
volumes:
  pgdata:

Start it and follow the logs:

docker compose up -d
docker compose ps
docker compose logs -f web

Tips

  • Keep data in volumes, not inside the container — otherwise it disappears when the container is recreated.
  • Don't expose database ports publicly: remove ports or use 127.0.0.1:5432:5432.
  • Clean up unused images regularly: docker system prune -a.
  • Turn on server backups — a VM snapshot includes your Docker volumes too.