Zurück zum Blog

Automatisches Docker Update-System

Automatisches Docker Update-System mit Vulnerability Tracking

1. Januar 2026 | 12 Min. Lesezeit | Infrastructure & Security

⚠️ Das Problem: 500+ kritische Schwachstellen

Bei einer Sicherheitsanalyse unserer Docker-Infrastruktur entdeckten wir:

  • 86 CRITICAL Vulnerabilities
  • 428 HIGH Vulnerabilities
  • 287 MEDIUM Vulnerabilities

Verteilt über 8 produktive Container-Stacks. Die manuelle Aktualisierung war zeitaufwändig, fehleranfällig und führte zu ungeplanten Ausfällen.

Lösung gefragt:

Wir brauchten eine automatisierte Lösung.


✨ Die Lösung: Intelligentes Update-System

Unser System aktualisiert automatisch jeden Sonntag um 04:00 UTC alle Container und:

  • Trackt Vulnerabilities (vorher/nachher Vergleich mit Trivy)
  • Führt automatische Rollbacks durch bei Fehlern
  • Generiert detaillierte Reports (Markdown)
  • Sendet Email-Benachrichtigungen (via n8n)
  • Erstellt Pre-Update Backups (7 Tage Retention)

📋 Update-Reihenfolge: Abhängigkeiten zuerst

Die Reihenfolge ist entscheidend – abhängige Services zuletzt:

Phase 1: Monitoring & Security (20 min)

  1. Monitoring Stack (Prometheus, Grafana)
  2. Wazuh SIEM

Phase 2: Core Infrastructure (25 min)

  1. Mailcow (Email – KRITISCH!)
  2. Authentik SSO (Login für alle Services)

Phase 3: User Services (25 min)

  1. Nextcloud (File Sharing)
  2. Directus + WebApp (CMS)

Phase 4: Automation & Proxy (20 min)

  1. n8n (Workflows)
  2. Traefik (Reverse Proxy – KRITISCH!)
Zeitplan:

Gesamtdauer: ~90 Minuten
Zeitpunkt: Sonntag, 04:00 UTC (nach Backup um 03:00)


⚙️ Der Update-Prozess für jeden Stack

1. Pre-Update Backup

# Aktuelle Versionen scannen
capture_pre_update_state "authentik"

# Vulnerability Scan
trivy image --format json authentik:2024.12 > before.json

# Docker Volumes sichern
tar czf /backup/authentik-20260101.tar.gz /volumes/authentik

2. Container Update

docker compose pull          # Neue Images
docker compose down          # Stoppen (60s timeout)
docker compose up -d         # Starten mit neuen Images

3. Health Checks (2-5 min)

Container-Level:

docker ps --filter "health=healthy"

Service-Level:

docker exec postgres-authentik pg_isready -U authentik
docker exec redis-authentik redis-cli PING
curl -Iks https://auth.matzka.cloud

4. Funktions-Tests

  • ✅ HTTPS Endpoint (200 oder 302)
  • ✅ API Endpoint erreichbar
  • ✅ PostgreSQL ready
  • ✅ Redis PING
  • ✅ Container healthy

5. Post-Update Scan

# Neue Versionen erfassen
capture_post_update_state "authentik"

# Erneuter Vulnerability Scan
trivy image --format json authentik:2024.12.1 > after.json

# Vergleich generieren
generate_vulnerability_diff before.json after.json

🔄 Automatisches Rollback bei Fehlern

Kritische Stacks (Mailcow, Authentik, Traefik) haben Auto-Rollback:

if ! run_stack_tests "authentik"; then
    # 1. Container stoppen
    docker compose down

    # 2. Backup wiederherstellen
    restore_backup "authentik" "20260101-040000"

    # 3. Alte Images starten
    docker compose up -d

    # 4. Benachrichtigung senden
    send_notification "rollback_success"
fi
Rollback-Zeit:

~2 Minuten ⚡


🔍 Vulnerability Tracking mit Trivy

Beispiel: Authentik Update

Status CRITICAL HIGH MEDIUM Image
Vor dem Update 6 28 12 ghcr.io/goauthentik/server:2024.12
Nach dem Update 6 28 12 Bereits auf neuester Version
💡 Wichtige Erkenntnis

Die meisten Vulnerabilities sind Upstream-Probleme:

  • ❌ Schwachstellen in Base-Images (Debian, Alpine)
  • ❌ Schwachstellen in Abhängigkeiten (SQLite, libxml, zlib)
  • ⏳ Warten auf neue Upstream-Releases

Unser System ist dennoch wertvoll:

  • ✅ Automatische Updates sobald verfügbar
  • ✅ Tracking der Vulnerability-Entwicklung
  • ✅ Dokumentation für Compliance

📧 Benachrichtigungen via n8n

Events

  1. start – Update beginnt
  2. stack_update_success – Stack erfolgreich
  3. stack_update_failure – Stack fehlgeschlagen
  4. rollback_initiated – Rollback gestartet
  5. complete – Alle Updates fertig

n8n Workflow

Webhook → Switch (Event Type) → Email Nodes
            ├─ start → Info Email 🚀
            ├─ success → Success Email ✅
            └─ failure → Alert Email ⚠️

Empfänger: admin@matzka.cloud (via Mailcow SMTP)


📂 Dateistruktur auf dem Server

/opt/docker/scripts/
├── update-stacks.sh              # Hauptscript
├── lib/
│   ├── common.sh                 # Logging, Utilities
│   ├── backup.sh                 # Backup/Restore
│   ├── testing.sh                # Health Checks
│   ├── reporting.sh              # Vulnerability Tracking
│   └── notification.sh           # n8n Webhook
├── stacks/                       # Stack-Updates
│   ├── 01-monitoring.sh
│   ├── 02-wazuh.sh
│   ├── 03-mailcow.sh
│   ├── 04-authentik.sh
│   ├── 05-nextcloud.sh
│   ├── 06-directus-webapp.sh
│   ├── 07-n8n.sh
│   └── 08-traefik.sh
└── config/
    └── update-config.env         # Konfiguration

⏰ Cron-Konfiguration

# Wöchentliche Updates: Jeden Sonntag 04:00 UTC
0 4 * * 0 /opt/docker/scripts/update-stacks.sh >> /opt/docker/logs/updates/cron.log 2>&1

🔧 Besondere Herausforderungen gelöst

1. Traefik Network Connectivity

Problem: Nach Update verlor Traefik Verbindung zu anderen Netzwerken
Symptom: HTTP 502 Bad Gateway

Lösung:

traefik:
  networks:
    - frontend
    - authentik-backend        # Explizit hinzugefügt
    - mailcow-network          # Explizit hinzugefügt

2. Mailcow Spezial-Behandlung

Mailcow nutzt eigene Namenskonvention und hat 15+ Container:

cd /opt/mailcow-dockerized
docker compose up -d

# Tests: SMTP (25, 587), IMAP (993), MariaDB, Redis

3. PostgreSQL Major Version Updates

Minor Updates (17.0 → 17.1): ✅ Automatisch
Major Updates (17 → 18): ⚠️ MANUELL (Migration erforderlich)


🎉 Erfolge nach 4 Wochen

Metriken

  • 28 automatische Updates durchgeführt
  • 100% Success Rate (kein Rollback nötig)
  • 0 ungeplante Ausfälle
  • ~5 Min. Downtime pro Stack
  • 90 Min. Gesamtdauer pro Lauf

Vulnerability Verbesserungen

Wo Updates verfügbar waren:

  • PostgreSQL: 17.0 → 17.1 (3 HIGH behoben)
  • Redis: 7.2 → 7.4 (1 CRITICAL behoben)
  • Nginx: 1.25 → 1.26 (2 MEDIUM behoben)

Wo keine Verbesserung möglich:

  • Authentik, Nextcloud, Directus: Bereits auf neuester Version
  • Base-Image Vulnerabilities: Warten auf Upstream

💡 Best Practices

1. Dependency Graph erstellen

Traefik (Reverse Proxy)
  └─ benötigt von: ALLE Services

Mailcow (SMTP)
  ├─ benötigt: Traefik
  └─ benötigt von: Authentik, Nextcloud, n8n

Authentik (SSO)
  ├─ benötigt: Mailcow, Traefik
  └─ benötigt von: Nextcloud, Directus

Update-Order: Von unten nach oben

2. Health Checks (3 Ebenen)

  1. Container: docker ps --filter "health=healthy"
  2. Service: PostgreSQL pg_isready, Redis PING
  3. Application: HTTPS, API Calls

3. Rollback-Strategie

  • Kritische Services: Automatisches Rollback
  • Unkritische Services: Nur Benachrichtigung

🎯 Fazit

Die Implementierung eines automatischen Update-Systems hat unsere Infrastruktur revolutioniert:

  • Keine vergessenen Updates
  • Vulnerability Tracking für Compliance
  • Automatische Rollbacks geben Sicherheit
  • Detaillierte Reports für Dokumentation
  • Zeit gespart: 2 Stunden/Woche

Das Wichtigste: Wir sind proaktiv statt reaktiv. Updates passieren automatisch, wir werden nur bei Problemen benachrichtigt.


📚 Open Source verfügbar

Repository:
📂 github.com/reinmatz/matzka-cloud
📁 Scripts: /scripts/ Directory

Technologie:
Bash, Docker Compose, Trivy, n8n, Mailcow


Kontakt