Watchtower - Automatic Container Updates

How-To Sep 3, 2022
Watchtower - Automatically Update Docker Containers - HedgeDoc

Watchtower - Automatically Update Docker Containers

Table of Contents

Overview

Watchtower by containerrr is a Docker application that will automatically scan the docker containers you are running and update them when a new and updated Docker image is pushed to the docker registry

In this guide I will show you how to:

  1. setup watchtower to update all containers automatically
  2. setup watchtower to send notifications when an update is available

Prerequisites

You need to have the following:

  • A linux machine with Docker installed
  • Have Portainer installed
  • An SMTP email Provider

:warning: Sometimes container updates may break the service altogether. If it is a major app like nextcloud which may be essential to you, it is recommended to manually update the container

Seting up Option 1

To set this up you simply need to do the following:

You can either set up a Portainer Stack or you can simply run a terminal docker run command:

$ docker run -d \ --name watchtower \ -v /var/run/docker.sock:/var/run/docker.sock \ containrrr/watchtower

Copy and paste the following Docker Compose YAML into the text window in Portainer:

version: "3" services: watchtower: image: containrrr/watchtower volumes: - /var/run/docker.sock:/var/run/docker.sock

Setting up Option 2

If you have essential services running that you cannot afford to lengthy downtimes on, I would recommend setting up method 2.

Watchtower will automatically send you an email notification when a container update is available.

Simply copy paste the following Docker Compose YAML, ensuring to read the comments:

:information_source: PLEASE NOTE THAT THE SCHEDULE ENV VARIABLE USES 6 DIGIT CRON NOTATION. GO HERE TO CONFIGURE. Below I have configured it to run at 4 AM everyday

version: '3.8' services: watchtower: image: containrrr/watchtower:latest container_name: watchtower environment: - 'WATCHTOWER_MONITOR_ONLY=true' - 'WATCHTOWER_NOTIFICATIONS=email' #tell watchtower to send emails - '[email protected]' - '[email protected]' - '[email protected]' - 'WATCHTOWER_NOTIFICATION_EMAIL_SERVER=smtp.domain.com' - 'WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD=password_for_user' - 'WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT=587' #configure accordingly - 'WATCHTOWER_NOTIFICATION_EMAIL_DELAY=2' - 'WATCHTOWER_SCHEDULE=* * * 4 * *' #Note Watchtower uses 6 digit cron expression - 'TZ=Europe/London' #Set timezone volumes: - /var/run/docker.sock:/var/run/docker.sock

And click Deploy Stack. You should receive an email of all the Apps that may have available updates!

Click here for some useful links

You’re done!

✅ And with that, you are now done! You have successfully notifications for container updates!

Tags

KVIS

I am the creator and publisher of this blog. Hope you found this guide useful!