Watchtower richtig konfigurieren - automatische Updates ohne böse Überraschungen
Watchtower richtig konfigurieren - automatische Updates ohne böse Überraschungen
Watchtower kann entweder ein nützliches Automatisierungswerkzeug oder ein zuverlässiger Produktions-Saboteur sein – je nach Konfiguration.
Grundkonfiguration
services:
watchtower:
image: containrrr/watchtower
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
WATCHTOWER_SCHEDULE: "0 0 3 * * *" # täglich um 3 Uhr
WATCHTOWER_CLEANUP: "true"
WATCHTOWER_INCLUDE_STOPPED: "false"
restart: unless-stopped
WATCHTOWER_SCHEDULE nutzt das erweiterte Cron-Format mit Sekunden: Sek Min Std Tag Mon Wochentag.
Benachrichtigungen einrichten
Ohne Benachrichtigung weiß man nicht was Watchtower getan hat:
environment:
# Gotify (self-hosted Push)
WATCHTOWER_NOTIFICATIONS: gotify
WATCHTOWER_NOTIFICATION_GOTIFY_URL: "https://gotify.example.com"
WATCHTOWER_NOTIFICATION_GOTIFY_TOKEN: "mytoken"
# Oder: E-Mail
WATCHTOWER_NOTIFICATIONS: email
WATCHTOWER_NOTIFICATION_EMAIL_FROM: "watchtower@example.com"
WATCHTOWER_NOTIFICATION_EMAIL_TO: "admin@example.com"
WATCHTOWER_NOTIFICATION_EMAIL_SERVER: "smtp.example.com"
WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT: "587"
WATCHTOWER_NOTIFICATION_EMAIL_SERVER_USER: "user"
WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD: "pass"
Startup-Nachricht unterdrücken (erzeugt sonst eine Benachrichtigung bei jedem Watchtower-Start):
environment:
WATCHTOWER_NO_STARTUP_MESSAGE: "true"
Nur bestimmte Container updaten (Scope)
Standardmäßig überwacht Watchtower alle laufenden Container. Besser: nur Container mit einem bestimmten Label updaten.
# Watchtower auf gelabelte Container beschränken
environment:
WATCHTOWER_LABEL_ENABLE: "true"
Container die Watchtower updaten soll bekommen das Label:
services:
myapp:
image: myapp:latest
labels:
com.centurylinklabs.watchtower.enable: "true"
Container die Watchtower ignorieren soll:
services:
criticaldb:
image: postgres:16
labels:
com.centurylinklabs.watchtower.enable: "false"
Produktive Dienste ausschließen
Niemals Produktiv-Datenbanken oder kritische Dienste automatisch updaten. Immer explizit opt-out setzen:
services:
db:
image: postgres:16
labels:
com.centurylinklabs.watchtower.enable: "false"
redis:
image: redis:7-alpine
labels:
com.centurylinklabs.watchtower.enable: "false"
Monitor-Only-Modus
Watchtower kann nur benachrichtigen, ohne tatsächlich zu updaten – nützlich um neue Image-Versionen zu entdecken ohne sie automatisch einzuspielen:
environment:
WATCHTOWER_MONITOR_ONLY: "true"
Einmaliges Update triggern
# Alle Container einmalig updaten ohne dauerhaft laufendem Watchtower
docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower --run-once
Empfohlene Konfiguration für Homelab
environment:
WATCHTOWER_SCHEDULE: "0 0 4 * * 0" # Sonntags um 4 Uhr
WATCHTOWER_CLEANUP: "true"
WATCHTOWER_NO_STARTUP_MESSAGE: "true"
WATCHTOWER_LABEL_ENABLE: "true" # Nur explizit markierte Container
WATCHTOWER_NOTIFICATIONS: gotify
WATCHTOWER_NOTIFICATION_GOTIFY_URL: "https://gotify.internal"
WATCHTOWER_NOTIFICATION_GOTIFY_TOKEN: "token"
Damit: Updates nur am Wochenende, nur für explizit markierte Container, mit Benachrichtigung.