Get Telegram Notifications for Watchtower Updates

Get Telegram Notifications for Watchtower Updates
Photo by Damian Kamp / Unsplash

Watchtower is a powerful tool for keeping your Docker containers up to date automatically. However, while it handles the updates, it doesn’t notify you when they happen—unless you set it up with notifications. I needed this for my own setup, so I figured I’d share it with the world while I was at it.


Step 1: Create a Telegram Bot

First, you'll need a Telegram bot to send the notifications. Here's how to set it up:

  1. Open a chat with BotFather on Telegram.
  2. Type /newbot and follow the instructions. You’ll need to give your bot a name and a username.
  3. Once your bot is created, you’ll receive an API token. This token is essential for connecting your Docker setup to Telegram.

Step 2: Get Your Chat ID

To send notifications to your Telegram account, you need your chat ID. Follow these steps:

  1. Start a conversation with your newly created bot (just send any message).
  2. In the same chat, search for and start a conversation with @get_id_bot. This bot will send you a message with your unique chat ID.

This chat ID is needed to direct the notifications to the correct chat (your Telegram account).


Step 3: Set Up Watchtower with Telegram Notifications

Now it’s time to configure Watchtower to use the Telegram bot you just created. You’ll need to add a couple of environment variables to your docker-compose.yml file. This tells Watchtower where to send the notifications.

Add the following lines under the environment section of your docker-compose.yml file:

environment:
    - WATCHTOWER_NOTIFICATIONS=shoutrrr
    - WATCHTOWER_NOTIFICATION_URL=telegram://<HTTP_API_TOKEN>@telegram?chats=<CHAT_ID>

Replace:

  • <HTTP_API_TOKEN> with the API token you got from BotFather.
  • <CHAT_ID> with the chat ID you received from @get_id_bot.

Step 4: (Re)start Watchtower

Once your configuration is set, restart Watchtower to apply the changes. Run this command in the terminal:

sudo docker-compose up -d --force-recreate

You should now receive a notification from your bot confirming that Watchtower is running. This message should look something like this:

Whenever a container is updated, you’ll also get a message like this:

This makes it easy to stay on top of updates without constantly monitoring the containers yourself.


Complete docker-compose Example

Here’s what your complete docker-compose.yml might look like after adding the necessary environment variables:

services:
  watchtower:
    image: containrrr/watchtower
    environment:
      - WATCHTOWER_NOTIFICATIONS=shoutrrr
      - WATCHTOWER_NOTIFICATION_URL=telegram://<HTTP_API_TOKEN>@telegram?chats=<CHAT_ID>
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    restart: always

Make sure to replace <HTTP_API_TOKEN> and <CHAT_ID> with your actual values.


Now, you can sit back and relax while Watchtower keeps your containers up to date and Telegram lets you know when something’s changed. Happy Docker-ing!