
With watchtower you can update the running version of your containerized app simply by pushing a new image to the Docker Hub or your own image registry.
Watchtower will pull down your new image, gracefully shut down your existing container and restart it with the same options that were used when it was deployed initially.
compose file :
services:
watchtower:
image: containrrr/watchtower:latest
container_name: watchtower
restart: always
volumes:
# This is required for Watchtower to interact with the Docker API
- /var/run/docker.sock:/var/run/docker.sock
environment:
- TZ=Asia/Kolkata
# Watchtower requires a 6-field cron expression (Seconds Minutes Hours Day Month Day-of-Week)
# "0 0 2 * * *" schedules it to run exactly at 2:00 AM every day.
- WATCHTOWER_SCHEDULE=0 0 2 * * *
# Optional Watchtower will automatically delete the old, leftover image whenever it updates a container to a new version:
- WATCHTOWER_CLEANUP=trueIn addition, I am adding the capability to delete old, leftover images whenever it updates a container when a new version is released, helping to clean and save space on the server.
