Running docker compose pull && docker compose up -d by hand every week gets old fast, especially when you self-host half a dozen apps on one VPS. Learning how to auto-update Docker containers with Watchtower labels takes that chore off your plate without handing Watchtower the keys to everything. Labels let you pick which containers update themselves, which stay pinned, and when updates run, so a bad upstream release cannot take down your whole stack at 3 a.m.
Watchtower is a small container that watches your other containers, pulls newer images, and restarts them when one appears. Left on its defaults it updates everything, which is fine for a test box and risky for a server hosting your WordPress site, file sync, and monitoring. Labels flip that: you tag the containers you trust to update, and Watchtower ignores the rest. This guide walks through that setup on a typical Ubuntu VPS.
How Watchtower Works on a VPS
Watchtower runs as a container with access to the Docker socket, usually mounted read-only at /var/run/docker.sock. On a schedule it asks each registry whether a newer image exists for your running containers. When it finds one, it stops the old container, pulls the new image, and starts a fresh one from the same configuration. Your volumes stay attached, so data survives the swap.
By default Watchtower updates every running container. That sounds convenient until a database image ships a breaking change or a major version of your reverse proxy renames a setting. Labels flip the logic: Watchtower only touches containers you marked. You can also set a schedule, a notification channel, and lifecycle hooks that run commands before and after an update, which is how you add a quick backup before the swap.
If your containers already restart on their own after a crash, you have half the safety net in place. A solid auto-restart setup for crashed Docker containers means a failed update still leaves the service trying to come back up instead of sitting dead until morning.
How to Auto-Update Docker Containers with Watchtower Labels Safely
Start with a compose file for Watchtower itself. The two settings that matter most are WATCHTOWER_LABEL_ENABLE=true, which tells Watchtower to respect labels, and a schedule so updates run when you choose. This example checks every Sunday at 04:00:
services:
watchtower:
image: containrrr/watchtower
container_name: watchtower
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
- WATCHTOWER_LABEL_ENABLE=true
- WATCHTOWER_SCHEDULE=0 0 4 * * SUN
- WATCHTOWER_CLEANUP=true
- WATCHTOWER_TIMEOUT=60s
command: --label-enable
WATCHTOWER_CLEANUP=true removes the old image after a successful update, which keeps disk usage down. The timeout gives a slow container a full minute to stop gracefully. Save the file as docker-compose.yml in its own folder, then run docker compose up -d.
Now mark a container for updates. In its own compose file, add this label:
labels:
- "com.centurylinklabs.watchtower.enable=true"
Any container without that label is invisible to Watchtower once label mode is on. Start with one low-risk service and watch one update cycle before labeling anything that holds user data.
Test the First Update Before You Trust It
Run Watchtower once in the foreground instead of waiting for Sunday:
docker compose run --rm watchtower --run-once --label-enable
Watch the output: it lists the containers it found, checks each image, and reports no updates or applies one. If it tries to update a container you did not label, stop and recheck your environment variables; a missing WATCHTOWER_LABEL_ENABLE is the usual cause. Once the dry run looks right, leave the scheduled container running.
Choosing Which Containers Get Labels
Not every service deserves automatic updates. Label stateless or easily rebuilt services first, and keep databases, password managers, and anything with a complex migration on manual updates:
- Safe to label: uptime monitors, dashboards, static sites, media servers, and small utilities with no database migrations.
- Label with care: apps with a database, such as Nextcloud or Ghost. Read the release notes before each major version, and consider pinning to a minor version tag like
nextcloud:29so Watchtower only moves within that line. - Do not label: databases themselves, your reverse proxy if it fronts production traffic, and any container you are actively debugging.
Pinning matters. If your compose file says image: postgres:16, Watchtower will never jump you to 17 on its own. If it says postgres:latest, it will, and a major-version jump can refuse to start against your old data directory. Use explicit tags everywhere, and treat :latest as a decision, not a default. If you want a fuller picture of the trade-offs, the comparison of Watchtower versus manual updates for self-hosted apps lays out where automation helps and where a human should stay in the loop.
Scheduling Updates Around Your Traffic
The default Watchtower interval checks every 24 hours at a random time, which is fine for a hobby server and sloppy for a site with real visitors. A watchtower update schedule gives you control. The format is standard six-field cron: seconds, minutes, hours, day of month, month, day of week.
| Schedule value | What it does | Good for |
|---|---|---|
0 0 4 * * SUN |
Every Sunday at 04:00 | Low-traffic blogs and personal stacks |
0 30 3 * * 1,4 |
Monday and Thursday at 03:30 | Stacks where you check logs each morning |
0 0 2 1 * * |
First day of the month at 02:00 | Conservative setups, one batch a month |
Pick a window when you are awake a few hours later, not the night before a busy day. If an update breaks something, you want to find out from your own checks, not from a visitor. Pair the schedule with notifications: Watchtower supports email, Slack, Telegram, and webhooks through environment variables, so a failed update lands in your inbox instead of sitting silent. A simple health check on top of that helps too; a health check for Docker containers on a VPS will tell you within minutes whether a freshly updated service actually came back up.
Adding a Safety Net Before Updates Run
Labels control what updates. Lifecycle hooks control what happens around the update. Watchtower can run a command inside a container before it stops it (pre-check or pre-update) and after it starts the new one (post-update). The most useful pre-update hook on a small VPS is a database dump.
For a WordPress stack, a pre-update hook that runs mysqldump into a mounted backup folder costs a few seconds and turns a bad update into a ten-minute restore. Keep the last few dumps and rotate them with a simple cron job. If you have never tested a restore, schedule one; a backup you have never restored is a guess, not a plan.
Two more habits keep updates boring. Keep a staging copy of anything critical, even a second container on another port, and let Watchtower update it a day earlier. And snapshot the VPS before labeling a new service, if your provider offers snapshots; the snapshot is the undo button for the whole server.
When an Update Breaks Something
A bad release will slip through eventually. Watchtower keeps the previous image on disk unless cleanup removed it, so docker images shows the old tag. Stop the broken container, start the previous image with the same compose file and the old tag, and confirm the service answers before touching anything else.
If cleanup already deleted the old image, pull the tag again from the registry; released tags stay available, which is another reason to pin versions instead of using :latest. After the rollback, remove the label from that service until you know what broke, and check the upstream release notes before re-enabling it.
Downtime is still possible during the swap, because Watchtower stops the old container before the new one starts: a gap of seconds to a minute for a single-container service. If that gap matters to you, read the guide on updating Docker containers without downtime before you automate anything that faces visitors.
Common Mistakes to Avoid
- Labeling everything on day one. Start with one or two services and add more over a month.
- Using
:lateston databases. A major-version jump can refuse your data directory and leave the service down. - Forgetting cleanup. Without
WATCHTOWER_CLEANUP=true, every update leaves an old image behind. Old images pile up fast on a small disk, so check disk usage monthly and read the guide on cleaning up old Docker images to free disk space if yours is already tight. - No notifications. Silent automation means silent failures. Send update results to a channel you actually read.
- Updating the reverse proxy automatically. If the proxy goes down, every site behind it goes down with it. Update it by hand.
Docker container auto-update done this way is a small, deliberate setup: opt-in labels, pinned image tags, a schedule you chose, and a backup before the swap. Put those four pieces in place and your containers stay current without you babysitting docker compose pull every weekend, and without a surprise release taking down the services your visitors depend on.