WatchTower 每隔几分钟就会通过 Docker Hub 检查已启动容器的版本,如果发现当前运行的容器版本低于最新版,WatchTower 会拉取最新镜像,然后优雅地关闭运行中的容器,最后使用相同的参数启动容器。WatchTower 也可以更新自身镜像。

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.

下文将展示如何安装 WawtchTower 并启用邮件通知

环境

  • Debian 10
    • Docker version 20.10.5, build 55c4c88

步骤

WatchTower 本身也被封装为容器,只需一行指令即可安装

docker run -d \
    --name watchtower \
    -v /var/run/docker.sock:/var/run/docker.sock \
    containrrr/watchtower

添加启动参数开启邮件通知

docker run -d \
  --name watchtower \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -e WATCHTOWER_NOTIFICATIONS=email \
  -e WATCHTOWER_NOTIFICATION_EMAIL_FROM=[发送方邮件地址] \
  -e WATCHTOWER_NOTIFICATION_EMAIL_TO=[接收方邮件地址] \
  -e WATCHTOWER_NOTIFICATION_EMAIL_SERVER=[邮件服务地址,例(QQ邮箱):smtp.qq.com] \
  -e WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT=587(根据邮件服务提供商填写) \
  -e WATCHTOWER_NOTIFICATION_EMAIL_SERVER_USER=[发送方邮件验证账户] \
  -e WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD=[发送方账户密码] \
  -e WATCHTOWER_NOTIFICATION_EMAIL_DELAY=2 \
  containrrr/watchtower

Continue reading “使用 WatchTower 自动更新 Docker 容器镜像”