Automating Docker container updates safely with Watchtower
Configure Watchtower in opt-in label mode with cron scheduling, image cleanup, and Discord or Telegram notifications for safe homelab updates.
Keeping 15+ homelab containers patched by hand doesn’t scale, but blindly auto-updating everything breaks databases and config schemas. This guide sets up Watchtower in opt-in label mode with off-peak cron scheduling, dangling image cleanup, and real-time Discord or Telegram notifications.
Maintenance notice (
containrrr/watchtowerarchived): The upstreamcontainrrr/watchtowerrepository was archived on December 17, 2025, and can hit Docker API compatibility issues on Docker Engine 29+. If you want to keep the exact same Compose config and labels, switch the image to the community drop-in fork (nickfedor/watchtower). For new setups, consider alternatives like WUD (What’s Up Docker), Diun, or Freshdock.
The manual update dilemma on a homelab
Once your homelab settles in—running Nginx Proxy Manager, Cloudflare DDNS, Portainer, AdGuard Home, and a handful of utilities—you quickly hit three operational headaches:
- Stale images and unpatched CVEs: Upstream maintainers ship fixes for OpenSSL, cURL, and runtime libraries every month, but manual
docker compose pullroutines get postponed until containers are months behind. - Blind auto-updates cause outages: Updating every container indiscriminately breaks stateful services. Letting PostgreSQL or MariaDB jump a major version automatically corrupts or rejects the existing data directory, and breaking config changes take down core apps overnight.
- SSD bloat from dangling images: Repeated pulls leave orphaned
<none>image layers sitting on disk until a small homelab SSD runs out of space.
The fix is a split policy: auto-update stateless utilities on a schedule, never touch stateful databases automatically, prune old images on every run, and send a notification whenever anything changes.
How Watchtower works under the hood
Watchtower runs as a lightweight daemon container with access to /var/run/docker.sock. On each cron tick, it inspects running containers, compares their local image SHA-256 digests against the remote registry, and recreates only the containers whose digest changed:
sequenceDiagram
autonumber
participant WT as Watchtower (04:00 Cron)
participant Sock as Docker Engine (/var/run/docker.sock)
participant Reg as Docker Hub / GHCR
participant Hook as Discord / Telegram
WT->>Sock: List running containers & labels
Sock-->>WT: Containers with watchtower.enable=true
loop Each opted-in container
WT->>Reg: Fetch remote image digest (SHA256)
Reg-->>WT: Latest manifest digest
alt Digest changed
WT->>Reg: Pull new image layers
WT->>Sock: Stop old container (SIGTERM)
WT->>Sock: Recreate with same networks, volumes & env
WT->>Sock: Remove old dangling image (rmi)
WT->>Hook: Send update summary
else Up to date
WT->>WT: Skip container
end
end
When a newer digest is found, Watchtower executes four steps in sequence:
- Reads the existing container’s runtime config (networks, port bindings, volumes, environment variables, restart policy).
- Sends
SIGTERMto shut down the running container cleanly. - Starts a new container from the updated image with the identical config and removes the old image layer when
WATCHTOWER_CLEANUP=trueis set. - Dispatches a summary report to Discord or Telegram via Shoutrrr.
Step 1: Configure Watchtower in opt-in mode
The single most important setting is opt-in mode (WATCHTOWER_LABEL_ENABLE=true). In Watchtower’s default opt-out mode, any new database container you spin up and forget to exclude becomes eligible for automatic updates on the very next cron cycle.
Define notification secrets in .env
Store your timezone and Shoutrrr webhook URL outside compose.yaml:
1
2
3
4
5
6
7
8
9
# .env (Watchtower stack directory)
TZ=Asia/Seoul
# Discord webhook URL (Shoutrrr format: discord://token@webhookid)
DISCORD_WEBHOOK_URL=discord://your-masked-token-xxxx@123456789012345678
# Optional Telegram format:
# telegram://bot_token@telegram?channels=chat_id
# TELEGRAM_WEBHOOK_URL=telegram://123456789:ABCdef-masked-token@telegram?channels=-100123456789
Watchtower bundles Shoutrrr for notifications. Notice that Discord’s standard URL (
https://discord.com/api/webhooks/<id>/<token>) reverses the segment order in Shoutrrr format:discord://<token>@<id>.
Write compose.yaml
Use a 6-field cron expression (seconds, minutes, hours, day, month, weekday) to run checks during off-peak hours—here, 4:00 AM daily:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# compose.yaml (Watchtower stack)
name: homelab-watchtower
services:
watchtower:
image: containrrr/watchtower:latest # Or nickfedor/watchtower:latest on Docker Engine 29+
container_name: watchtower
restart: unless-stopped
volumes:
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock:rw # Needs rw to stop, remove, and recreate containers
environment:
- TZ=${TZ}
# 1. Run daily at 04:00:00 (6-field cron: sec min hour dom mon dow)
- WATCHTOWER_SCHEDULE=0 0 4 * * *
# 2. Opt-in safety mode: only update containers with enable=true label
- WATCHTOWER_LABEL_ENABLE=true
# 3. Prune previous image versions after updating
- WATCHTOWER_CLEANUP=true
# 4. Ignore stopped containers
- WATCHTOWER_INCLUDE_STOPPED=false
# 5. Recreate containers one by one instead of all at once
- WATCHTOWER_ROLLING_RESTART=true
# 6. Shoutrrr notification config
- WATCHTOWER_NOTIFICATIONS=shoutrrr
- WATCHTOWER_NOTIFICATION_URL=${DISCORD_WEBHOOK_URL}
- WATCHTOWER_NOTIFICATION_TEMPLATE={{- range . -}}Container: {{.Name}} ({{.ImageName}})\nStatus: {{.State}}\n{{- end -}}
# 7. Send startup confirmation message
- WATCHTOWER_NO_STARTUP_MESSAGE=false
labels:
# Opt Watchtower itself into updates
- "com.centurylinklabs.watchtower.enable=true"
networks:
- npm-network
networks:
npm-network:
external: true
Deploy the stack:
1
docker compose up -d
Step 2: Label stateless vs. stateful containers
With WATCHTOWER_LABEL_ENABLE=true, Watchtower ignores every container by default. Classify your homelab services before adding labels:
| Category | Auto-update policy | Typical examples |
|---|---|---|
| Stateless utilities | Opt in (enable=true) | Cloudflare DDNS, AdGuard Home, IT-Tools, Speedtest Tracker |
| Ingress / proxies | Opt in with off-peak cron | Nginx Proxy Manager (config & certs persisted in volumes) |
| Databases | Never auto-update (enable=false) | PostgreSQL, MariaDB, MySQL, Redis (with AOF/RDB persistence) |
| Security-critical vaults | Manual review & update | Vaultwarden, Authelia, LLDAP |
Services safe to opt in
Add this label to stateless containers whose config lives cleanly on mounted volumes:
1
2
labels:
- "com.centurylinklabs.watchtower.enable=true"
- Cloudflare DDNS (
favonia/cloudflare-ddns): Stateless Go binary; restarting takes a second and loses nothing. - Nginx Proxy Manager (
jc21/nginx-proxy-manager): Persists SQLite state and certificates on volumes; minor and patch updates apply cleanly. - AdGuard Home / Pi-hole & utility web apps: Low-risk updates that benefit directly from regular security patches.
Services to keep manual
Leave the label off—or explicitly set it to false as documentation for your future self:
1
2
labels:
- "com.centurylinklabs.watchtower.enable=false"
- Relational databases (PostgreSQL, MariaDB, MySQL): Jumping from PostgreSQL 16 to 17 without
pg_dump/pg_upgradetriggersFATAL: database files are incompatible with serverand puts the container in a crash loop. Pin major versions incompose.yaml(e.g.,postgres:16-alpine) and upgrade during planned maintenance. - Password vaults (Vaultwarden): Review release notes and back up the SQLite/PostgreSQL database before upgrading so a schema bug doesn’t lock you out of your credentials.
When not to use Watchtower at all: If you run a GitOps workflow where every image digest or version tag is pinned in Git and updated via Renovate or Dependabot PRs, Watchtower creates drift between what’s declared in Git and what’s running on the host. Use Watchtower only for stacks that intentionally track floating tags like :latest or :2.
Step 3: Test updates and notifications on demand
You don’t have to wait until 4:00 AM to verify your labels and Discord webhook. Trigger a single pass immediately with --run-once:
1
docker exec -it watchtower /watchtower --run-once
When Watchtower finds an updated digest, it posts a report straight to your notification channel:
1
2
3
4
5
6
[Watchtower Update Report]
Container: cloudflare-ddns (favonia/cloudflare-ddns:latest)
Status: Updated (pulled new digest: sha256:4a8f9c...)
Container: nginx-proxy-manager (jc21/nginx-proxy-manager:latest)
Status: Updated (pulled new digest: sha256:7b2e1a...)
Checking one message in the morning tells you exactly which containers rolled overnight without digging through docker ps.
Reverse proxy caveats and checklist
If you include Nginx Proxy Manager in your opt-in list, keep two operational details in mind:
- Brief 5–10 second ingress drop: While Watchtower stops the old NPM container and starts the new one, inbound port 443 traffic drops briefly. Scheduling checks at
0 0 4 * * *(4:00 AM) and enablingWATCHTOWER_ROLLING_RESTART=truekeeps the blip invisible. - Read-write Docker socket exposure: Watchtower requires
/var/run/docker.sock:rwbecause it stops, removes, and recreates containers. Never publish any HTTP API ports (WATCHTOWER_HTTP_API_UPDATE) to the public internet, and keep the container isolated on internal networks only.
Pre-flight checklist
- Using
nickfedor/watchtower:latest(or an alternative like WUD/Diun) if running Docker Engine 29+. WATCHTOWER_LABEL_ENABLE=trueis set so new containers are excluded by default.WATCHTOWER_CLEANUP=trueandWATCHTOWER_ROLLING_RESTART=trueare enabled.- Databases and password vaults have pinned image tags and no
enable=truelabel. docker exec -it watchtower /watchtower --run-oncedelivers a test notification to Discord or Telegram.