Watchtower – Automated Docker Updates with Discord Notifications

Watchtower is a container where you can deploy on your docker instance and it will be checking your current deployed containers if the need to be updated to the latest image. If a container needs an update then Watchtower will stop the container pull the new image and redeploy the updated with all its previous settings and configurations.
Website: https://containrrr.dev/watchtower/

My Deployment

I deploy everything through the Portainer UI as a stack so if you need to create to a docker compose yaml file you can easily convert it.

Portainer Stack

services:
 watchtower:
    image: containrrr/watchtower:latest
    container_name: watchtower
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/Los_Angeles
      - WATCHTOWER_CLEANUP=true
      - WATCHTOWER_INCLUDE_STOPPED=true
      - WATCHTOWER_REVIVE_STOPPED=false
      - WATCHTOWER_SCHEDULE=0 30 4 * * *
      - WATCHTOWER_NOTIFICATIONS=shoutrrr
      - WATCHTOWER_NOTIFICATION_URL=discord://2670338zx-0-603Cx21719A6_A-D898y987B5B9ACxA68Ax__2A6z67212z_BDy9zC36@0198310207064143205
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    network_mode: host
    restart: unless-stopped

Configuration

In my both my docker instances I have Watchtower configured pretty similar the only difference is that they run one hour apart.
First you will need to set your timezone for Watchtower.

TZ=America/Los_Angeles

I have Watchtower configured in a way that it will check for updates every day at 3:30 AM for my local instance and the one that is hosted in Cloud VPS it will be running at 4:30 AM. Watchtower uses the Cron format but has one extra field on the front for seconds.
WATCHTOWER_SCHEDULE=0 30 4 * * *

WATCHTOWER_SCHEDULE=0 30 4 * * *

Watchtower uses the Cron format but has one extra field on the front for seconds.

So with all the information above you should be able to configure your deployment with the correct timezone and set how often you would like it to check for updates for your containers.

Notifications

Watchtower uses the shoutrrr is a notification library that can work with a various different services like Email, Discord, Slack, Pushbullet and many more. For my case I decided to go with Discord and send my notifications via Webhook to a specific channel to my Discord Server.

You can check how to create a Discord Webhook here:
Intro to Webhooks

Once you have followed the steps above you should have a Webhook URL that looks something like this:

https://discord.com/api/webhooks/0198310207064143205/2670338zx-0-603Cx21719A6_A-D898y987B5B9ACxA68Ax__2A6z67212z_BDy9zC36

You can safely delete the following part

https://discord.com/api/webhooks/

Now we are left with 2 parts that look like this:

0198310207064143205/2670338zx-0-603Cx21719A6_A-D898y987B5B9ACxA68Ax__2A6z67212z_BDy9zC36

We will need to convert it to the following format discord://Part1@Part2

WATCHTOWER_NOTIFICATION_URL=discord://2670338zx-0-603Cx21719A6_A-D898y987B5B9ACxA68Ax__2A6z67212z_BDy9zC36@0198310207064143205

Final Words

Once you have finished configuring everything then Watchtower will run at the specified day and time and if it finds and updates will send a message to your Discord Channel via the Webhook similar to the screenshot below.