Updating your Docker containers can be a time consuming thing, but it doesn’t have to be like that!
Watchtower is an open-source tool which keeps an watchful eye on your active Docker containers. It is designed to automate the process of updating the containers with the latest available image from a Docker registry. When a new image is available, Watchtower will pull the latest image and restart the container with the new image.
While I love the idea of automation and having my Docker containers up to date, I would like to be in control. As a rule of thumb I never update anything critical right away. I usually wait for a couple of days / weeks (depending on the system and its community) to see if there are some bugs in the release. As soon as I’m confident I’ll update the containers. However I do want to monitor if and when a new image is available and for this I also use Watchtower.
How to install Watchtower?
With the below Docker Compose which you can use in Portainer, you get to do just that. Here Watchtower Monitor Only mode is turned on, so it will download the new image and send you an email. Then it’s up to you to restart the container with the new image.
Under WATCHTOWER_SCHEDULE I’ve made sure that Watchtower checks all my containers every Monday morning at 07:00.
version: '2.1'
services:
watchtower:
image: containrrr/watchtower
container_name: WatchTower
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
- TZ=Europe/Amsterdam
- WATCHTOWER_MONITOR_ONLY=true
- WATCHTOWER_SCHEDULE=0 0 07 * * MON
- WATCHTOWER_CLEANUP=true
- WATCHTOWER_NOTIFICATIONS=email
- WATCHTOWER_NOTIFICATION_EMAIL_FROM=you@gmail.com
- WATCHTOWER_NOTIFICATION_EMAIL_TO=you@gmail.com
- WATCHTOWER_NOTIFICATION_EMAIL_SERVER=smtp.gmail.com
- WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD=your_gmail_app_password
- WATCHTOWER_NOTIFICATION_EMAIL_SUBJECTTAG=subject_of_your_emails
- WATCHTOWER_NOTIFICATION_EMAIL_SERVER_USER=you@gmail.com
- WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT=587
restart: unless-stopped
How to use Watchtower?
As soon as you deploy the above Docker Compose, the Watchtower container will immediately start monitoring your containers. There is no other settings or whatsoever to define, that’s it.
If you would like it to also install the new image as well, then no worries. The new container will use the exact same options as the original Docker container had. So it’ll not touch port bindings, volume mounts, environment variables or any other setting.
Conclusion:
Watchtower automates Docker container updates upon new image additions to a registry. It’s highly customizable with optional arguments like filter by enable label, rolling restart, auto cleanup and more. This make Watchtower ideal for maintaining your Docker containers with ease!