Home Server › Containers

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.

Automating Docker container updates safely with Watchtower

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/watchtower archived): The upstream containrrr/watchtower repository 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:

  1. Stale images and unpatched CVEs: Upstream maintainers ship fixes for OpenSSL, cURL, and runtime libraries every month, but manual docker compose pull routines get postponed until containers are months behind.
  2. 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.
  3. 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:

  1. Reads the existing container’s runtime config (networks, port bindings, volumes, environment variables, restart policy).
  2. Sends SIGTERM to shut down the running container cleanly.
  3. Starts a new container from the updated image with the identical config and removes the old image layer when WATCHTOWER_CLEANUP=true is set.
  4. 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:

CategoryAuto-update policyTypical examples
Stateless utilitiesOpt in (enable=true)Cloudflare DDNS, AdGuard Home, IT-Tools, Speedtest Tracker
Ingress / proxiesOpt in with off-peak cronNginx Proxy Manager (config & certs persisted in volumes)
DatabasesNever auto-update (enable=false)PostgreSQL, MariaDB, MySQL, Redis (with AOF/RDB persistence)
Security-critical vaultsManual review & updateVaultwarden, 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_upgrade triggers FATAL: database files are incompatible with server and puts the container in a crash loop. Pin major versions in compose.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:

  1. 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 enabling WATCHTOWER_ROLLING_RESTART=true keeps the blip invisible.
  2. Read-write Docker socket exposure: Watchtower requires /var/run/docker.sock:rw because 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=true is set so new containers are excluded by default.
  • WATCHTOWER_CLEANUP=true and WATCHTOWER_ROLLING_RESTART=true are enabled.
  • Databases and password vaults have pinned image tags and no enable=true label.
  • docker exec -it watchtower /watchtower --run-once delivers a test notification to Discord or Telegram.
This post is licensed under CC BY 4.0 by the author.