Keep Docker Containers Up To Date With Watchtower

Keep Docker Containers Up To Date With Watchtower

What is Watchtower?

The purpose of Watchtower is to keep all or select Docker containers up to date at all times without requiring user intervention. Watchtower will also perform cleanup of the images which are replaced so that they will not take up unnecessary space. When an updated container image is found it will be pulled, shutdown, and restarted with the same configuration.

What arguments can be configured?

Watchtower contains many different arguments like configuring notifications when containers are updated or filtering of containers. There is a nice list of arguments and the docker-compose environment variable with examples in their documentation.

Example Docker-Compose

    watchtower:
        image: containrrr/watchtower:latest
        container_name: watchtower
        environment:
          WATCHTOWER_NOTIFICATIONS: email
          WATCHTOWER_NOTIFICATION_EMAIL_FROM: from@gmail.com
          WATCHTOWER_NOTIFICATION_EMAIL_TO: to@gmail.com
          WATCHTOWER_NOTIFICATION_EMAIL_SERVER_USER: admin@gmail.com
          WATCHTOWER_NOTIFICATION_EMAIL_SERVER: mail.domain.com
          WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD: password
          WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT: 26
          WATCHTOWER_POLL_INTERVAL: 28800
          WATCHTOWER_CLEANUP: "true"
          WATCHTOWER_NOTIFICATION_EMAIL_DELAY: 2
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock
        restart: always

Conclusion

I’ve been using Watchtower for over a month now and I haven’t had any major issues with it. I only had an issue with one container which depended on another container and for some reason would never start up properly after Watchtower updated and attempted to restart it. I’ve since replaced that container and haven’t had any other issues. If a setup where minimal interaction is desired and keeping all Docker containers up to date is a goal then I recommend Watchtower.