Watchtower — Automated Docker Container Image Updates
Runs as a container itself, polls registries for new image tags, and gracefully redeploys running containers when updates appear.
先审查再安装
这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。
npx -y tokrepo@latest install 1487461c-3919-11f1-9bc6-00163e2b0d79 --target codex先 dry-run,确认写入项后再运行此命令。
What it is
Watchtower is a Docker container that monitors other running containers and automatically updates them when new images are pushed to their registries. It polls container registries at configurable intervals, pulls updated images, and gracefully stops and restarts containers with the same configuration.
Watchtower targets anyone running Docker containers in production or on home servers who wants automatic updates without manual intervention. It handles the entire lifecycle: detect, pull, stop, and restart.
How it saves time or tokens
Manually checking for Docker image updates and redeploying containers is tedious and easy to forget. Watchtower automates this entirely. It preserves container configurations (ports, volumes, environment variables) during updates, so you do not need to re-specify startup parameters. Notifications via email, Slack, or webhooks keep you informed about what was updated and when.
How to use
- Start Watchtower to monitor all containers:
docker run -d --name watchtower \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower --interval 300 --cleanup
- Or monitor only specific containers by label:
# Add label to containers you want updated
docker run -d --label com.centurylinklabs.watchtower.enable=true my-app
# Run Watchtower with label filter
docker run -d --name watchtower \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower --label-enable --interval 300
Example
# docker-compose.yml with Watchtower
services:
watchtower:
image: containrrr/watchtower
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: --interval 3600 --cleanup --notifications-level info
restart: unless-stopped
my-app:
image: myregistry/my-app:latest
labels:
- com.centurylinklabs.watchtower.enable=true
ports:
- '8080:8080'
restart: unless-stopped
Related on TokRepo
- DevOps Tools — Container and infrastructure management tools
- Self-Hosted Tools — Self-hosted infrastructure automation
This tool integrates with standard development workflows and requires minimal configuration to get started. It is available as open-source software with documentation and community support through the official repository. The project follows semantic versioning for stable releases.
For teams evaluating this tool, the key advantage is reducing manual work in repetitive tasks. The automation provided by the built-in features means less custom code to maintain and fewer integration points to manage. This translates directly to lower maintenance costs and faster iteration cycles.
Common pitfalls
- Watchtower requires access to the Docker socket (
/var/run/docker.sock), which grants full control over all containers; restrict access and do not expose it on untrusted networks. - Automatic updates can introduce breaking changes; use specific image tags or a staging environment rather than
:latestin production to control when updates apply. - The
--cleanupflag removes old images after updates to prevent disk space buildup; without it, old images accumulate over time.
常见问题
Yes. Watchtower supports private Docker registries with authentication. Mount your Docker config.json file or set registry credentials via environment variables so Watchtower can pull from private repositories.
Yes. Use the --label-enable flag to only update containers with a specific label. Alternatively, add the com.centurylinklabs.watchtower.enable=false label to containers you want to exclude.
There is a brief period between stopping the old container and starting the new one. For zero-downtime updates, you need a load balancer and multiple container instances. Watchtower is best suited for single-instance containers where brief interruptions are acceptable.
Watchtower supports email, Slack, Microsoft Teams, Gotify, and webhook notifications. Configure notification settings via environment variables or command-line flags.
Watchtower is widely used in production, especially for home servers and small deployments. For mission-critical production systems, consider using CI/CD pipelines with manual approval gates instead of fully automated updates.
引用来源 (3)
- Watchtower GitHub— Watchtower automatically updates running Docker containers
- Watchtower Documentation— Watchtower supports notification via email, Slack, and webhooks
- Watchtower Usage Guide— Watchtower preserves container configuration during updates
讨论
相关资产
Keel — Automated Kubernetes Workload Updates
Keel is a Kubernetes operator that automates Helm, DaemonSet, StatefulSet, and Deployment updates when new container images are pushed to a registry, with approval workflows and notification support.
Diun — Docker Image Update Notifier
Get notified the moment a Docker image you depend on is updated on any registry, with support for Discord, Slack, email, and 15+ notification channels.
Uncloud — Lightweight Container Orchestration Across Docker Hosts
A lightweight tool for deploying and managing containerized applications across a network of Docker hosts. Bridges the gap between Docker Compose and Kubernetes, providing multi-host orchestration without the complexity.
Docker Compose — Define and Run Multi-Container Applications
Docker Compose lets you define multi-container application stacks in a single YAML file and manage their full lifecycle with simple CLI commands.