Watchtower - 自动更新 Docker 镜像与容器
git 地址:https://github.com/containrrr/watchtower
Docker images
docker pull containrrr/watchtower:i386-0.3.
docker pull containrrr/watchtower:i386-latest
docker pull containrrr/watchtower:amd64-0.3.
docker pull containrrr/watchtower:amd64-latest
docker pull containrrr/watchtower:armhf-0.3.
docker pull containrrr/watchtower:armhf-latest
docker pull containrrr/watchtower:arm64v8-0.3.
docker pull containrrr/watchtower:arm64v8-latest
快速开始
Watchtower 本身被打包为 Docker 镜像,因此可以像运行任何其他容器一样运行它:(然后所有容器都会自动更新,也包括 Watchtower 本身)
docker run -d \
--name watchtower \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower
选项参数
$ docker run --rm containrrr/watchtower -h Watchtower automatically updates running Docker containers whenever a new image is released.
More information available at https://github.com/containrrr/watchtower/. Usage:
watchtower [flags] Flags:
-a, --api-version string api version to use by docker client (default "1.24")
-c, --cleanup remove previously used images after updating
-d, --debug enable debug mode with verbose logging
--enable-lifecycle-hooks Enable the execution of commands triggered by pre- and post-update lifecycle hooks
-h, --help help for watchtower
-H, --host string daemon socket to connect to (default "unix:///var/run/docker.sock")
-S, --include-stopped Will also include created and exited containers
-i, --interval int poll interval (in seconds) (default )
-e, --label-enable watch containers where the com.centurylinklabs.watchtower.enable label is true
-m, --monitor-only Will only monitor for new images, not update the containers
--no-pull do not pull any new images
--no-restart do not restart any containers
--notification-email-delay int Delay before sending notifications, expressed in seconds
--notification-email-from string Address to send notification emails from
--notification-email-server string SMTP server to send notification emails through
--notification-email-server-password string SMTP server password for sending notifications
--notification-email-server-port int SMTP server port to send notification emails through (default )
--notification-email-server-tls-skip-verify
Controls whether watchtower verifies the SMTP server's certificate chain and host name.
Should only be used for testing. --notification-email-server-user string SMTP server user for sending notifications
--notification-email-subjecttag string Subject prefix tag for notifications via mail
--notification-email-to string Address to send notification emails to
--notification-gotify-token string The Gotify Application required to query the Gotify API
--notification-gotify-url string The Gotify URL to send notifications to
--notification-msteams-data The MSTeams notifier will try to extract log entry fields as MSTeams message facts
--notification-msteams-hook string The MSTeams WebHook URL to send notifications to
--notification-slack-channel string A string which overrides the webhook's default channel. Example: #my-custom-channel
--notification-slack-hook-url string The Slack Hook URL to send notifications to
--notification-slack-icon-emoji string An emoji code string to use in place of the default icon
--notification-slack-icon-url string An icon image URL string to use in place of the default icon
--notification-slack-identifier string A string which will be used to identify the messages coming from this watchtower instance (default "watchtower")
-n, --notifications strings notification types to send (valid: email, slack, msteams, gotify)
--notifications-level string The log level used for sending notifications. Possible values: panic, fatal, error, warn, info or debug (default "info")
--remove-volumes remove attached volumes before updating
--revive-stopped Will also start stopped containers that were updated, if include-stopped is active
-R, --run-once Run once now and exit
-s, --schedule string the cron expression which defines when to update
-t, --stop-timeout duration timeout before a container is forcefully stopped (default 10s)
-v, --tlsverify
自动清除旧镜像
官方给出的默认启动命令在长期使用后会堆积非常多的标签为 none 的旧镜像,如果放任不管会占用大量的磁盘空间。要避免这种情况可以加入 --cleanup 选项,这样每次更新都会把旧的镜像清理掉。
docker run -d \
--name watchtower \
--restart unless-stopped \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower \
--cleanup
--cleanup 选项可以简写为 -c:
docker run -d \
--name watchtower \
--restart unless-stopped \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower -c
选择性自动更新
某些容器可能需要稳定的运行,经常更新或重启可能会造成一些问题,这时我们可以使用一些选项参数来选择与控制容器的更新。
容器更新列表
假设我们只想更新 nginx、redis 这两个容器,我们可以把容器名称追加到启动命令的最后面,就像下面这个例子:
docker run -d \
--name watchtower \
--restart unless-stopped \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower -c \
nginx redis
博主觉得把需要更新的容器名称写在启动命令中不利于管理,于是想了个更好的方法,建立一个更新列表文件。
$ cat ~/.watchtower.list
aria2-pro
unlockmusic
mtg
...
通过变量的方式去调用这个列表:
docker run -d \
--name watchtower \
--restart unless-stopped \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower -c \
$(cat ~/.watchtower.list)
这样只需要调整列表后删除 Watchtower 容器并重新执行上面的命令重新启动 Watchtower 即可。
设置单个容器自动更新特征
给容器中添加 com.centurylinklabs.watchtower.enable 这个 LABEL 并设置它的值为 false,或者在启动命令中加入 --label com.centurylinklabs.watchtower.enable=false 参数可以排除相应的容器。下面这个例子是博主的 openwrt-mini 镜像的容器启动命令,Watchtower 将永远忽略它的更新,即使它包含在自动更新列表中
docker run -d \
--name openwrt-mini \
--restart always \
--network openwrt \
--privileged \
--label com.centurylinklabs.watchtower.enable=false \
p3terx/openwrt-mini \
/sbin/init
当容器启动命令中加入 --label com.centurylinklabs.watchtower.enable=true 参数,并且给 Watchtower 加上 --label-enable 选项时,Watchtower 将只更新这些包含此参数的容器。
docker run -d \
--name watchtower \
--restart unless-stopped \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower -c \
--label-enable
--label-enable 可以简写为 -e:
docker run -d \
--name watchtower \
--restart unless-stopped \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower -ce
因为需要在容器启动时进行设置,且设置后就无法直接更改,只能重建容器,所以这种方式的灵活性不如更新列表法。尤其是在设置 com.centurylinklabs.watchtower.enable=false 参数后容器将永远被 Watchtower 忽略,也包括后面将要提到的手动更新方式,所以一般不推荐这样做,除非你愿意手动重建的原生方式更新。
设置自动更新检查频率
默认情况下 Watchtower 每 5 分钟会轮询一次,如果你觉得这个频率太高了可以使用如下选项来控制更新检查的频率,但二者只能选择其一。
--interval,-i- 设置更新检测时间间隔,单位为秒。比如每隔 1 个小时检查一次更新:
docker run -d \
--name watchtower \
--restart unless-stopped \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower -c \
--interval
--schedule,-s- 设置定时检测更新时间。格式为 6 字段 Cron 表达式,而非传统的 5 个字段。比如每天凌晨 2 点检查一次更新:
docker run -d \
--name watchtower \
--restart unless-stopped \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower -c \
--schedule "0 2 * * * *"
手动更新
前面的使用方式都是让 Watchtower 以 detached(后台)模式在运行并自动更新容器,而 Watchtower 也支持以 foreground(前台)模式来使用,即运行一次退出并删掉容器,来实现手动更新容器。这对于偶尔更新一次那些不在自动更新列表中的容器非常有用。
对于 foreground 模式,需要加上 --run-once 这个专用的选项。下面的例子 Docker 会运行一次 Watchtower 并检查 aria2-pro 容器的基础镜像更新,最后删掉本次运行创建的 Watchtower 容器。
docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower -c \
--run-once \
aria2-pro
--run-once 可以简写为 -R:
docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower -cR \
aria2-pro
需要注意的是当这个容器设置过 com.centurylinklabs.watchtower.enable=false 参数时不会更新。
Watchtower - 自动更新 Docker 镜像与容器的更多相关文章
- watchtower 自动更新容器的工具
watchtower 自动更新容器的工具 安装 使用docker docker run -d \ --name watchtower \ -v /var/run/docker.sock:/var/ru ...
- Docker容器化【Docker镜像与容器相关命令】
# Docker 学习目标: 掌握Docker基础知识,能够理解Docker镜像与容器的概念 完成Docker安装与启动 掌握Docker镜像与容器相关命令 掌握Tomcat Nginx 等软件的常用 ...
- Docker镜像和容器
本节内容: 安装Docker 卸载docker 镜像基本操作 容器基本操作 一.安装Docker Docker 对 Linux 内核版本的最低要求是3.10,如果内核版本低于 3.10 会缺少一些运行 ...
- docker系列四之docker镜像与容器的常用命令
docker镜像与容器的常用命令 一.概述 docker的镜像于容器是docker中两个至关重要的概念,首先给各位读者解释一下笔者对于这两个概念的理解.镜像,我们从字面意思上看,镜子里成像,我们人 ...
- Dockerfile自动制作Docker镜像(二)—— 其它常用命令
Dockerfile自动制作Docker镜像(二)-- 其它常用命令 前言 a. 本文主要为 Docker的视频教程 笔记. b. 环境为 CentOS 7.0 云服务器 c. 上一篇:Dockerf ...
- Dockerfile 自动制作 Docker 镜像(一)—— 基本命令
Dockerfile 自动制作 Docker 镜像(一)-- 基本命令 前言 a. 本文主要为 Docker的视频教程 笔记. b. 环境为 CentOS 7.0 云服务器 c. 上一篇:手动制作Do ...
- docker镜像和容器的导出导入
本文介绍docker镜像和容器的导入导出,用于迁移.备份.升级等场景.主要用到export.import.save.load四个方法. 原文地址:代码汇个人博客 http://www.codehui. ...
- docker镜像与容器
目录 docker镜像与容器 概述 分层存储 镜像与容器 删除镜像与容器 将容器中的改动提交到镜像 慎用 docker commit--构建镜像推荐使用dockerfile docker镜像与容器 概 ...
- 快速批量删除 docker 镜像或容器
原文:快速批量删除 docker 镜像或容器 点击在我的博客 xuxusheng.com 中查看,有更好的排版哦~ docker 本身并没有提供批量删除的功能,当有大量的镜像或者容器需要删除的时候,手 ...
随机推荐
- for循环运用,三角形
用for循环打出三角形.倒三角形.金字塔.99乘法表 三角形: 打出如图三角形,分析行数与*个数的关系,用for循环 for(var i=0;i<5;++i){//i表示行数 var str=& ...
- queue stack for STL
前不久发现自己vector有些不会了,于是想起了queue和stack. 有一个小故事,,,某天我跟自己打赌我queue没有写博园,结果打开一看竟然不知什么时候写过了,而且(QAQ)还有一定的浏览量了 ...
- 再见了Antirez永远的Redis之神
其实antirez(Redis作者)退出Redis维护一发布我就在很多咨询网站上面看到了,当时也没太多感慨. 今天比较有空想去看看霉霉Twitter的,然后看到了antirez,我就又一次回顾了他的退 ...
- PHP linkinfo() 函数
定义和用法 linkinfo() 函数返回有关一个硬连接的信息. 该函数返回设备 ID,如果失败则返回 FALSE. 语法 linkinfo(path) 参数 描述 path 必需.规定要检查的路径. ...
- PHP __construct() 函数
实例 函数创建一个新的 SimpleXMLElement 对象,然后输出 body 节点的内容:高佣联盟 www.cgewang.com <?php $note=<<<XML ...
- 最新 laravel5.8 连接redis集群
简介 Redis 是一个开源的,高级键值对存储数据库.由于它包含 字符串 , 哈希 , 列表 , 集合 , 和 有序集合 这些数据类型,所以它通常被称为数据结构服务器. 在使用 Laravel 的 R ...
- mysql优化:explain 和 profile
此文转自:https://blog.csdn.net/hanjungua8144/article/details/84317829 一.SQL查询语句优化基本思路和原则 优化更需要优化的Query.定 ...
- JVM详解之:类的加载链接和初始化
目录 简介 加载 运行时常量池 类加载器 链接 验证 准备 解析 初始化 总结 简介 有了java class文件之后,为了让class文件转换成为JVM可以真正运行的结构,需要经历加载,链接和初始化 ...
- Pytest单元测试框架:插件-allure-pytest环境搭建并在本地生成一个测试报告
之前写了allure-pytest的官方文档啃的内容,有些交流的朋友,实践起来没什么头绪,所以就有了这篇文章,也给自己填个坑 第一步:搭建Allure.JDK环境 1. 搭建JDK环境 不装jdk你会 ...
- win7(64位)使用DEBUG
win7 64位好像是不能直接打开DOS进行DEUBG的,于是查找相应解决方案 开始看其他人的帖子,写得语焉不详,后来一查,居然是抄百度的.....自己不觉得low吗... 参考百度经验的回答http ...