Log inSign up

Update running containers automatically with Watchtower

Watchtower is a container that watches the Docker socket, pulls newer images for the tags your containers use and recreates them with the same settings. Start it with a schedule and --cleanup, limit it to labelled containers, and check its project status first: the original repository is no longer actively developed, so a docker compose pull job run by a systemd timer is a solid alternative.

Topic: Containers and PaaS · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13 · Updated 2026-12-03

What does Watchtower actually do?

Watchtower compares the image digest behind each running container tag with the digest in the registry, and when they differ it pulls the new image, stops the container, and starts a replacement with the same name, volumes, networks and environment. It only follows tags. A container started from postgres:17 will move to newer 17.x builds, while one pinned to an exact digest never changes. That makes your tag choice the real update policy, so pick tags that match the amount of change you accept.

You need Docker Engine first; follow the Docker Engine tutorial or start from the Docker app image.

What is the maintenance status of the original project?

The widely used containrrr/watchtower project has stopped active development and its repository was archived by the maintainers, so new Docker Engine releases may not be tested against it. Several community forks continue the code under different image names. Before you install, read the current state of whichever image you plan to use, check when it last had a release, and decide whether you are comfortable giving it access to the Docker socket. If you prefer fewer moving parts, the systemd timer approach later in this guide uses only Docker itself.

One known symptom of an old client meeting a new daemon is an error saying the client API version is too old. Watchtower reads the DOCKER_API_VERSION variable, so you can set it to the API version that docker version reports for the server.

How do you run Watchtower on a schedule?

Run it as a container with the Docker socket mounted, a cron schedule and cleanup of replaced images. The schedule uses six fields, with seconds first:

docker version --format '{{.Server.APIVersion}}'

sudo docker run -d --name watchtower --restart unless-stopped \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -e TZ=UTC \
  -e DOCKER_API_VERSION=1.47 \
  containrrr/watchtower \
  --schedule "0 30 4 * * *" --cleanup

Replace 1.47 with the value the first command prints, or drop that line if the default works. This checks every container at 04:30 UTC each day. The --cleanup flag removes the old image after a successful swap, which stops disk usage from creeping up; see the Docker cleanup guide for everything else that piles up. Confirm it started cleanly:

sudo docker logs watchtower

How do you choose which containers get updated?

Opt in by label so nothing changes by surprise. Start Watchtower with --label-enable and add the label only to containers that are safe to update unattended:

services:
  web:
    image: nginx:stable
    labels:
      - com.centurylinklabs.watchtower.enable=true
  db:
    image: postgres:17
    # no label: updated by hand after reading release notes

Databases, anything with migrations, and services where a restart drops user sessions are good candidates to leave out. You can also run Watchtower with --monitor-only, which reports available updates without touching anything, and then update by hand.

How do you get notified about updates?

Watchtower sends notices through shoutrrr URLs, which cover chat services, email and generic webhooks. Set the URL as an environment variable when you create the container:

-e WATCHTOWER_NOTIFICATION_URL="generic+https://hooks.example.net/watchtower" \
-e WATCHTOWER_NOTIFICATIONS_LEVEL=info

For email, route through an authenticated relay on port 587 rather than direct delivery. Outgoing port 25 is not something to plan around on a VPS; ask support with a ticket if direct mail matters to you.

How do you update images from a private registry?

Mount a Docker credentials file into the container so Watchtower can authenticate. Log in once on the host, then point Watchtower at the resulting file:

sudo docker login ghcr.io
sudo docker run -d --name watchtower --restart unless-stopped \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v /root/.docker/config.json:/config.json:ro \
  containrrr/watchtower --schedule "0 30 4 * * *" --cleanup --label-enable

Use a token with read access only. The socket mount already grants root level control of the host, so treat the Watchtower container with the same care as an SSH key.

How do you update with a systemd timer instead?

A short service and timer can pull and recreate a Compose project on a schedule with no extra container. Create the service unit:

sudo tee /etc/systemd/system/compose-update.service >/dev/null <<'EOF'
[Unit]
Description=Pull and restart the notes stack
Requires=docker.service
After=docker.service

[Service]
Type=oneshot
WorkingDirectory=/srv/notes
ExecStart=/usr/bin/docker compose pull --quiet
ExecStart=/usr/bin/docker compose up -d --remove-orphans
ExecStartPost=/usr/bin/docker image prune -f
EOF

Then the timer:

sudo tee /etc/systemd/system/compose-update.timer >/dev/null <<'EOF'
[Unit]
Description=Weekly stack update

[Timer]
OnCalendar=Sun *-*-* 04:30:00
RandomizedDelaySec=15m
Persistent=true

[Install]
WantedBy=timers.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now compose-update.timer
systemctl list-timers compose-update.timer

docker compose up -d only recreates services whose image or configuration changed, so unchanged containers keep running. Run sudo systemctl start compose-update.service once and read journalctl -u compose-update to confirm it works. The project layout is the one from the Docker Compose guide.

How do you roll back a bad update?

Keep the previous tag written down and pin to it. In Compose, change image: to the last good version and run docker compose up -d. If --cleanup already removed the old image, Docker simply pulls it again. For extra safety before risky upgrades, take a database dump first, and consider the daily backups add-on, which keeps whole disk copies you can restore through a support ticket.

Plans that fit this guide

Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.

All prices
PlanFits becauseSizeMonthlyOrder from
A1-2a few small containers kept current1 vCPU, 2 GB RAM, 50 GB NVMe$7.20/mo$43.20 for 6 months
A2-4a full stack updated on a timer2 vCPU, 4 GB RAM, 100 GB NVMe$14.40/mo$43.20 for 3 months

Questions about Automatic updates with Watchtower

Does Watchtower update Docker Engine itself?

No. It only replaces containers. Docker Engine and the operating system are updated through apt, for example with unattended upgrades.

Will Watchtower restart a container with the latest tag every night?

Only if the registry has a new digest for that tag. If nothing changed upstream, the container is left alone.

Is it safe to auto update databases?

It is risky. Major versions often need a dump and restore, so leave database containers unlabelled and update them by hand.

Can I run Watchtower once instead of on a schedule?

Yes. Add --run-once and remove -d; it checks, updates and exits, which works well from your own script.

Which alternative needs the least software?

The systemd timer with docker compose pull and up -d uses only Docker and systemd, and its log lands in the journal next to everything else.