Raja's Exocortex

Watchtower Auto Update Docker Containers

Watchtower can be used to keep all running docker containers up to date. Ensure container tags are used correctly to ensure minor version and security updates are performed, but not major versions.

Only running containers that have watchtower.enable=true will be updated. After updating the old container image will be deleted.

Eg. docker tag postgres:14 will update to Postgres version 14.1, 14.2, etc, but not to Postgres 15.

Note: containrrr/watchtower is deprecated, migrating to nickfedor/watchtower.

Daily Auto Updates

# docker-compose file to start up watchtower, docker container auto updating service
# to start the container run:
#    docker-compose up -d
#
# Note: nickfedor/watchtower service will auto update this container
# Note2: on Ubuntu apparmor can prevent watchtower from shutting down containers,
#        to fix it run:  sudo aa-remove-unknown
#        And ./run.sh to verify

name: watchtower-localhost

services:
  watchtower:
    image: nickfedor/watchtower
    container_name: watchtower.localhost
    restart: always

    mem_limit: 32M

    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /etc/localtime:/etc/localtime:ro

    labels:
      - com.centurylinklabs.watchtower.enable=true

    # Update containers at 4.15am and delete old images after update
    command: --label-enable --cleanup --schedule "0 15 4 * * *"

Updating Manually

#!/bin/sh
# Filename: run.sh
# Manually run watchtower once to update all docker containers

docker run --rm \
    -v /var/run/docker.sock:/var/run/docker.sock \
    nickfedor/watchtower --cleanup --label-enable --run-once