Anleitungen

Ein produktiver Docker-Compose-Stack auf einem VPS

Fortgeschritten25 Min. LesezeitAktualisiert 27. Juni 2026
Kurze Antwort

Ein brauchbarer Produktions-Stack ist Caddy für automatisches TLS, Ihre Anwendung, PostgreSQL und Redis, definiert in einer Compose-Datei mit benannten Volumes und Health Checks. Auf 8 GB RAM mit NVMe bewältigt dieser Stack beträchtlichen Verkehr, und ein Snapshot vor jedem Deploy macht Rollback zu einer Zwei-Minuten-Operation.

01 Docker aus dem offiziellen Repository installieren

Distribution packages lag significantly. The convenience script is fine on a fresh instance.

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

02 Die Compose-Datei schreiben

Caddy obtains and renews certificates automatically, which removes the single most common source of production breakage.

services:
  caddy:
    image: caddy:2-alpine
    restart: unless-stopped
    ports: ["80:80", "443:443", "443:443/udp"]
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data
  app:
    build: .
    restart: unless-stopped
    depends_on: { db: { condition: service_healthy } }
    environment:
      DATABASE_URL: postgres://app:${DB_PASS}@db:5432/app
  db:
    image: postgres:17-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: app
      POSTGRES_PASSWORD: ${DB_PASS}
    volumes: [pgdata:/var/lib/postgresql/data]
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U app"]
      interval: 10s
volumes: { caddy_data: {}, pgdata: {} }

03 Caddy konfigurieren

Three lines is a complete TLS-terminating reverse proxy with automatic certificate renewal.

app.example.com {
  encode zstd gzip
  reverse_proxy app:8000
}

04 Die Datenbank sichern, nicht den Container

A file copy of a running Postgres data directory produces a corrupt backup that appears to succeed. Dump it properly.

docker compose exec -T db pg_dump -U app app | zstd > /backups/app-$(date +%F).sql.zst

05 Vor jedem Deploy einen Snapshot erstellen

Free, instant, and it converts a failed deployment from an incident into a rollback.

Häufig gestellte Fragen

Wie viel RAM wird dafür benötigt?

Summieren Sie die Speicherlimits der Container und fügen Sie etwa 1 GB für den Host hinzu. Dieser Stack ist in 8 GB gut aufgehoben.

Sollte ich stattdessen Docker Swarm oder Kubernetes verwenden?

Nicht für einen einzelnen Server. Compose ist das richtige Werkzeug, bis du wirklich mehr als einen Knoten hast.