Thursday, November 11, 2021
Keep Docker containers up to date with Watchtower
At home I run Docker containers like Unifi Controller, Adguard Home, Spotweb, Calibre Web, Uptime Kuma and several others.
These applications receive regular updates and new features, which requires me to manually update them (pull new image, remove running container, and start new container).
This manual process can be eliminated by using Watchtower, a small Docker container that periodically checks for updates. When a new image is found the running container will be automatically updated.
Running Watchtower is easy, just execute the following command:
sudo docker run -d \ --name watchtower \ -v /var/run/docker.sock:/var/run/docker.sock \ -e TZ=Europe/Amsterdam \ containrrr/watchtower \ --cleanup \ --include-stopped \ --interval 43200
The command above will result in Watchtower checking for updates every 12 hours. It will perform this check for all containers (including stopped containers) and will remove old images after updating (to save on disk space).
Most of my containers run the "latest" tag and some are pinned to a specific release to make sure these automated updates do not break anything without me knowing.
You can provide Watchtower with loads of configuration options (such as the interval, credentials to private docker registries, webhook to notify a Slack channel when an update is found and much more), see the documentation for more information.