偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

推薦一款自動更新Docker鏡像與容器的神器Watchtower

系統(tǒng) Linux
Watchtower 是一個(gè)可以實(shí)現(xiàn)自動化更新 Docker 基礎(chǔ)鏡像與容器的實(shí)用工具。

前言

Docker 容器的部署有一種在手機(jī)上裝 App 的感覺,但 Docker 容器并不會像手機(jī) App 那樣會自動更新,而如果我們需要更新容器一般需要以下四個(gè)步驟:

  •  停止容器:docker stop <CONTAINER>
  •  刪除容器:docker rm <CONTAINER>
  •  更新鏡像:docker pull <IMAGE>
  •  啟動容器:docker run <ARG> ... <IMAGE>

停止容器這個(gè)步驟可以在刪除容器時(shí)使用 -f 參數(shù)來代替,即使這樣還是需要三個(gè)步驟。如果部署了大量的容器需要更新使用這種傳統(tǒng)的方式工作量是巨大的。

Watchtower 是一個(gè)可以實(shí)現(xiàn)自動化更新 Docker 基礎(chǔ)鏡像與容器的實(shí)用工具。它監(jiān)視正在運(yùn)行的容器以及相關(guān)的鏡像,當(dāng)檢測到 reg­istry 中的鏡像與本地的鏡像有差異時(shí),它會拉取最新鏡像并使用最初部署時(shí)相同的參數(shù)重新啟動相應(yīng)的容器,一切好像什么都沒發(fā)生過,就像更新手機(jī)上的 App 一樣。

快速開始

Watch­tower 本身被打包為 Docker 鏡像,因此可以像運(yùn)行任何其他容器一樣運(yùn)行它: 

  1. docker run -d \  
  2.     --name watchtower \  
  3.     -v /var/run/docker.sock:/var/run/docker.sock \  
  4.     containrrr/watchtower 

然后所有容器都會自動更新,也包括 Watch­tower 本身。

選項(xiàng)參數(shù) 

  1. $ docker run --rm containrrr/watchtower -h  
  2. Watchtower automatically updates running Docker containers whenever a new image is released.  
  3. More information available at https://github.com/containrrr/watchtower/.  
  4. Usage:  
  5.   watchtower [flags]  
  6. Flags:  
  7.   -a, --api-version string                          api version to use by docker client (default "1.24")  
  8.   -c, --cleanup                                     remove previously used images after updating  
  9.   -d, --debug                                       enable debug mode with verbose logging  
  10.       --enable-lifecycle-hooks                      Enable the execution of commands triggered by pre- and post-update lifecycle hooks  
  11.   -h, --help                                        help for watchtower  
  12.   -H, --host string                                 daemon socket to connect to (default "unix:///var/run/docker.sock")  
  13.   -S, --include-stopped                             Will also include created and exited containers  
  14.   -i, --interval int                                poll interval (in seconds) (default 300) 
  15.   -e, --label-enable                                watch containers where the com.centurylinklabs.watchtower.enable label is true  
  16.   -m, --monitor-only                                Will only monitor for new images, not update the containers  
  17.       --no-pull                                     do not pull any new images  
  18.       --no-restart                                  do not restart any containers  
  19.       --notification-email-delay int                Delay before sending notifications, expressed in seconds  
  20.       --notification-email-from string              Address to send notification emails from  
  21.       --notification-email-server string            SMTP server to send notification emails through  
  22.       --notification-email-server-password string   SMTP server password for sending notifications  
  23.       --notification-email-server-port int          SMTP server port to send notification emails through (default 25)  
  24.       --notification-email-server-tls-skip-verify  
  25.                                                     Controls whether watchtower verifies the SMTP server's certificate chain and host name.  
  26.                                                     Should only be used for testing.  
  27.       --notification-email-server-user string       SMTP server user for sending notifications  
  28.       --notification-email-subjecttag string        Subject prefix tag for notifications via mail  
  29.       --notification-email-to string                Address to send notification emails to  
  30.       --notification-gotify-token string            The Gotify Application required to query the Gotify API  
  31.       --notification-gotify-url string              The Gotify URL to send notifications to 
  32.       --notification-msteams-data                   The MSTeams notifier will try to extract log entry fields as MSTeams message facts  
  33.       --notification-msteams-hook string            The MSTeams WebHook URL to send notifications to  
  34.       --notification-slack-channel string           A string which overrides the webhook's default channel. Example: #my-custom-channel  
  35.       --notification-slack-hook-url string          The Slack Hook URL to send notifications to  
  36.       --notification-slack-icon-emoji string        An emoji code string to use in place of the default icon  
  37.       --notification-slack-icon-url string          An icon image URL string to use in place of the default icon  
  38.       --notification-slack-identifier string        A string which will be used to identify the messages coming from this watchtower instance (default "watchtower") 
  39.    -n, --notifications strings                        notification types to send (valid: email, slack, msteams, gotify)  
  40.       --notifications-level string                  The log level used for sending notifications. Possible values: panic, fatal, error, warn, info or debug (default "info") 
  41.       --remove-volumes                              remove attached volumes before updating  
  42.       --revive-stopped                              Will also start stopped containers that were updated, if include-stopped is active  
  43.   -R, --run-once                                    Run once now and exit  
  44.   -s, --schedule string                             the cron expression which defines when to update  
  45.   -t, --stop-timeout duration                       timeout before a container is forcefully stopped (default 10s)  
  46.   -v, --tlsverify                                   use TLS and verify the remote 

自動清除舊鏡像

官方給出的默認(rèn)啟動命令在長期使用后會堆積非常多的標(biāo)簽為 none 的舊鏡像,如果放任不管會占用大量的磁盤空間。要避免這種情況可以加入 --cleanup 選項(xiàng),這樣每次更新都會把舊的鏡像清理掉。 

  1. docker run -d \  
  2.     --name watchtower \  
  3.     --restart unless-stopped \  
  4.     -v /var/run/docker.sock:/var/run/docker.sock \  
  5.     containrrr/watchtower \  
  6.     --cleanup 

--cleanup 選項(xiàng)可以簡寫為 -c: 

  1. docker run -d \  
  2.     --name watchtower \  
  3.     --restart unless-stopped \  
  4.     -v /var/run/docker.sock:/var/run/docker.sock \  
  5.     containrrr/watchtower -c 

選擇性自動更新

某些容器可能需要穩(wěn)定的運(yùn)行,經(jīng)常更新或重啟可能會造成一些問題,這時(shí)我們可以使用一些選項(xiàng)參數(shù)來選擇與控制容器的更新。

  1.  容器更新列表

假設(shè)我們只想更新 nginx、redis 這兩個(gè)容器,我們可以把容器名稱追加到啟動命令的最后面,就像下面這個(gè)例子: 

  1. docker run -d \  
  2.     --name watchtower \  
  3.     --restart unless-stopped \  
  4.     -v /var/run/docker.sock:/var/run/docker.sock \  
  5.     containrrr/watchtower -c \  
  6.     nginx redis 

博主覺得把需要更新的容器名稱寫在啟動命令中不利于管理,于是想了個(gè)更好的方法,建立一個(gè)更新列表文件。 

  1. $ cat ~/.watchtower.list  
  2. aria2-pro 
  3. unlockmusic  
  4. mtg  
  5. ... 

通過變量的方式去調(diào)用這個(gè)列表: 

  1. docker run -d \  
  2.     --name watchtower \  
  3.     --restart unless-stopped \  
  4.     -v /var/run/docker.sock:/var/run/docker.sock \  
  5.     containrrr/watchtower -c \  
  6.     $(cat ~/.watchtower.list) 

這樣只需要調(diào)整列表后刪除 Watch­tower 容器并重新執(zhí)行上面的命令重新啟動 Watch­tower 即可。

      2.  設(shè)置單個(gè)容器自動更新特征

給容器添加 com.centurylinklabs.watchtower.enable 這個(gè) LA­BEL 并設(shè)置它的值為 false,或者在啟動命令中加入 --label com.centurylinklabs.watchtower.enable=false 參數(shù)可以排除相應(yīng)的容器。下面這個(gè)例子是博主的 openwrt-mini 鏡像的容器啟動命令,Watch­tower 將永遠(yuǎn)忽略它的更新,即使它包含在自動更新列表中。 

  1. docker run -d \  
  2.     --name openwrt-mini \  
  3.     --restart always \  
  4.     --network openwrt \  
  5.     --privileged \  
  6.     --label com.centurylinklabs.watchtower.enable=false \  
  7.     p3terx/openwrt-mini \  
  8.     /sbin/init 

當(dāng)容器啟動命令中加入 --label com.centurylinklabs.watchtower.enable=true 參數(shù),并且給 Watch­tower 加上 --label-enable 選項(xiàng)時(shí),Watch­tower 將只更新這些包含此參數(shù)的容器。 

  1. docker run -d \  
  2.     --name watchtower \  
  3.     --restart unless-stopped \  
  4.     -v /var/run/docker.sock:/var/run/docker.sock \  
  5.     containrrr/watchtower -c \  
  6.     --label-enable 

--label-enable 可以簡寫為 -e: 

  1. docker run -d \  
  2.     --name watchtower \  
  3.     --restart unless-stopped \  
  4.     -v /var/run/docker.sock:/var/run/docker.sock \  
  5.     containrrr/watchtower -ce 

因?yàn)樾枰谌萜鲉訒r(shí)進(jìn)行設(shè)置,且設(shè)置后就無法直接更改,只能重建容器,所以這種方式的靈活性不如更新列表法。尤其是在設(shè)置 com.centurylinklabs.watchtower.enable=false 參數(shù)后容器將永遠(yuǎn)被 Watch­tower 忽略,也包括后面將要提到的手動更新方式,所以一般不推薦這樣做,除非你愿意手動重建的原生方式更新。

設(shè)置自動更新檢查頻率 

默認(rèn)情況下 Watch­tower 每 5 分鐘會輪詢一次,如果你覺得這個(gè)頻率太高了可以使用如下選項(xiàng)來控制更新檢查的頻率,但二者只能選擇其一。

--interval, -i - 設(shè)置更新檢測時(shí)間間隔,單位為秒。比如每隔 1 個(gè)小時(shí)檢查一次更新: 

  1. docker run -d \  
  2.     --name watchtower \  
  3.     --restart unless-stopped \  
  4.     -v /var/run/docker.sock:/var/run/docker.sock \  
  5.     containrrr/watchtower -c \  
  6.     --interval 3600 

--schedule, -s - 設(shè)置定時(shí)檢測更新時(shí)間。格式為 6 字段 Cron 表達(dá)式,而非傳統(tǒng)的 5 字段,即第一位是秒。比如每天凌晨 2 點(diǎn)檢查一次更新: 

  1. docker run -d \  
  2.     --name watchtower \  
  3.     --restart unless-stopped \  
  4.     -v /var/run/docker.sock:/var/run/docker.sock \  
  5.     containrrr/watchtower -c \  
  6.     --schedule "0 0 2 * * *" 

手動更新

前面的使用方式都是讓 Watch­tower 以 detached(后臺)模式在運(yùn)行并自動更新容器,而 Watch­tower 也支持以 foreground(前臺)模式來使用,即運(yùn)行一次退出并刪掉容器,來實(shí)現(xiàn)手動更新容器。這對于偶爾更新一次那些不在自動更新列表中的容器非常有用。

對于 foreground 模式,需要加上 --run-once 這個(gè)專用的選項(xiàng)。下面的例子 Docker 會運(yùn)行一次 Watch­tower 并檢查 aria2-pro 容器的基礎(chǔ)鏡像更新,最后刪掉本次運(yùn)行創(chuàng)建的 Watch­tower 容器。 

  1. docker run --rm \  
  2.     -v /var/run/docker.sock:/var/run/docker.sock \  
  3.     containrrr/watchtower -c \  
  4.     --run-once \  
  5.     aria2-pro 

--run-once 可以簡寫為 -R: 

  1. docker run --rm \  
  2.     -v /var/run/docker.sock:/var/run/docker.sock \  
  3.     containrrr/watchtower -cR \  
  4.     aria2-pro 

需要注意的是當(dāng)這個(gè)容器設(shè)置過 com.centurylinklabs.watchtower.enable=false 參數(shù)時(shí)不會更新。

尾巴

以上是博主在使用 Watch­tower 中總結(jié)的一些使用方式和方法,當(dāng)然它還有一些其它的功能與使用方式,比如電子郵件通知、監(jiān)視私人注冊表的鏡像、更新遠(yuǎn)程主機(jī)上的容器等,這些對于一般用戶來說可能很少會用到,所以這里就不贅述了,感興趣的小伙伴可以去研究 Watchtower 官方文檔。 

 

責(zé)任編輯:龐桂玉 來源: 奇妙的Linux世界
相關(guān)推薦

2022-08-14 19:33:24

Watchtower開源Docker

2019-02-25 10:18:43

工具代碼測試

2022-10-09 10:11:30

Python爬蟲神器

2020-08-28 10:40:13

PythonFaker數(shù)據(jù)

2024-01-25 10:40:11

AutoProfil開源分析工具

2021-04-27 09:00:59

PythonAidLearning編程神器

2014-01-13 15:00:51

InxiLinux硬件

2020-04-30 10:45:14

IDEA代碼神器工具

2024-03-26 12:22:03

Visio軟件

2022-04-20 09:26:08

Mock前端開發(fā)工具

2024-08-22 12:35:37

2025-04-07 08:10:00

2023-09-06 08:19:53

2015-03-30 14:15:55

自動更新Android

2020-02-17 07:20:22

SSH遠(yuǎn)程連接工具Linux

2024-12-27 12:10:58

2023-06-08 08:46:37

Motrix下載工具

2023-10-31 08:03:33

開源電子簽名組件

2020-10-14 11:05:10

Java開發(fā)IDEA

2020-12-15 07:54:40

工具Hutoolgithub
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號