国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Watchtower—自動更新docker鏡像與容器

這篇具有很好參考價值的文章主要介紹了Watchtower—自動更新docker鏡像與容器。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

1. 簡述

Watchtower 是一個可以實現(xiàn)自動化更新 Docker 基礎鏡像與容器的實用工具。它監(jiān)視正在運行的容器以及相關的鏡像,當檢測到 reg-istry 中的鏡像與本地的鏡像有差異時,它會拉取最新鏡像并使用最初部署時相同的參數(shù)重新啟動相應的容器,

2. 啟動

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

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

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

選項參數(shù):

$ 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 300)
  -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 25)
      --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                                   use TLS and verify the remote

3. 使用示例

3.1 自動清除舊鏡像

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

docker run -d \
    --name watchtower \
    --restart unless-stopped \
    -v /var/run/docker.sock:/var/run/docker.sock \
    containrrr/watchtower -c

3.2 選擇性自動更新

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

  1. 容器更新列表

    # 只更新 nginx、redis 這兩個容器,可以把容器名稱追加到啟動命令的最后面
    docker run -d \
        --name watchtower \
        --restart unless-stopped \
        -v /var/run/docker.sock:/var/run/docker.sock \
        containrrr/watchtower -c \
        nginx redis
    
    
    # 建立一個更新列表文件, 通過變量的方式去調(diào)用這個列表:
    $ 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)
    
    
  2. 設置單個容器自動更新特征

給容器添加 com.centurylinklabs.watchtower.enable 這個 LA-BEL 并設置它的值為 false,或者在啟動命令中加入 --label com.centurylinklabs.watchtower.enable=false 參數(shù)可以排除相應的容器。

# openwrt-mini 鏡像的容器啟動命令,Watch-tower 將永遠忽略它的更新,即使它包含在自動更新列表中
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 參數(shù),
#并且給 Watch-tower 加上 --label-enable 選項時,Watch-tower 將只更新這些包含此參數(shù)的容器
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 參數(shù)后容器將永遠被 Watch-tower 忽略,包括后面將要提到的手動更新方式,所以一般不推薦這樣做,除非你愿意手動重建的原生方式更新

3.3 僅監(jiān)控更新情況,不更新

使用 --monitor-only 將僅監(jiān)控新鏡像并發(fā)送通知,不會更新容器。

4. 設置自動更新檢查頻率

默認情況下 Watch-tower5 分鐘會輪詢一次,可以使用:--interval, -i - 設置更新檢測時間間隔,單位為秒。比如每隔 1 個小時檢查一次更新:

docker run -d \
    --name watchtower \
    --restart unless-stopped \
    -v /var/run/docker.sock:/var/run/docker.sock \
    containrrr/watchtower -c \
    --interval 3600

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

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

5. 手動更新

加上 --run-once 這個專用的選項,運行一次退出并刪掉容器,來實現(xiàn)手動更新容器。這對于偶爾更新一次那些不在自動更新列表中的容器非常有用。

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 參數(shù)時不會更新。

6. 發(fā)送提示

可以通過電子郵件、Slack 、MSTeams 以及 Gotify 發(fā)送通知

docker run -d \
  --name watchtower \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -e WATCHTOWER_NOTIFICATIONS=email \
  -e WATCHTOWER_NOTIFICATION_EMAIL_FROM=fromaddress@gmail.com \
  -e WATCHTOWER_NOTIFICATION_EMAIL_TO=toaddress@gmail.com \
  -e WATCHTOWER_NOTIFICATION_EMAIL_SERVER=smtp.gmail.com \
  -e WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT=587 \
  -e WATCHTOWER_NOTIFICATION_EMAIL_SERVER_USER=fromaddress@gmail.com \
  -e WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD=app_password \
  -e WATCHTOWER_NOTIFICATION_EMAIL_DELAY=2 \
  containrrr/watchtower

7. watchtower獲取私有鏡像服務的認證方式

docker run -d --name watchtower --restart always -v /root/.docker/config.json:/config.json -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower -c

/root/.docker/config.json文件,在docker登錄阿里云的私有鏡像服務后會自動生成,生成的位置應該是在登錄后的根目錄文章來源地址http://www.zghlxwxcb.cn/news/detail-469157.html

到了這里,關于Watchtower—自動更新docker鏡像與容器的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內(nèi)容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • Jenkins+GitLab+Docker搭建前端自動化構建鏡像容器部署(無本地證書,映射證書)

    Jenkins+GitLab+Docker搭建前端自動化構建鏡像容器部署(無本地證書,映射證書)

    前言 ?? 需提前安裝環(huán)境及知識點: 1、Docker搭建及基礎操作 2、DockerFile文件描述 3、Jenkins搭建及基礎點 ?? 目的: 將我們的前端項目打包成一個鏡像容器并自動發(fā)布部署,可供隨時pull訪問 1、在當前項目的根目錄創(chuàng)建Dockerfile文件并寫入如下代碼: 代碼片段詳細描述: 注意

    2024年02月15日
    瀏覽(23)
  • 記一次線上mysql出錯:由于docker自動拉取最新mysql鏡像導致mysql容器無法啟動

    記一次線上mysql出錯:由于docker自動拉取最新mysql鏡像導致mysql容器無法啟動

    我隨便寫寫,你們隨便看看 環(huán)境背景:在docker中部署mysql鏡像,通過portainer管理docker容器 簡單說下過程:docker里mysql的時區(qū)沒有設置,導致相差8小時,通過增加TZ=Asiz/Shanghai環(huán)境變量,然后重啟容器來生效。結果重啟的時候始終無法啟動起來,后來發(fā)現(xiàn)是自動升級了mysql鏡像版

    2024年02月07日
    瀏覽(25)
  • 這里做一篇關于wsl2更新到最新版本使用鏡像網(wǎng)絡,但是docker創(chuàng)建的容器不能被訪問的問題(困擾了我一整天)

    這里做一篇關于wsl2更新到最新版本使用鏡像網(wǎng)絡,但是docker創(chuàng)建的容器不能被訪問的問題(困擾了我一整天)

    在windows2023年9月的一次更新中,wsl2支持了新的網(wǎng)絡模式鏡像模式,他能夠通過localhost地址從wsl2內(nèi)部連接到windows的127.0.0.1地址 ##相當于是和本地主機擁有同一個ip 原wsl2是不支持的,雖說是net網(wǎng)絡模式,可訪問主機,主機也可訪問wsl2,同時也可上網(wǎng),但是不能被網(wǎng)絡訪問,如

    2024年04月16日
    瀏覽(24)
  • docker 保存鏡像、容器與導入鏡像容器

    可以通過以下步驟將Docker鏡像導出到另一臺計算機上: 在本地計算機上使用以下命令將Docker鏡像保存為tar文件: 其中,image-name是要導出的Docker鏡像的名稱。 將保存的tar文件傳輸?shù)搅硪慌_計算機上,可以使用scp命令或其他文件傳輸工具。 在目標計算機上使用以下命令將tar文

    2024年02月13日
    瀏覽(27)
  • docker導出鏡像、容器打鏡像

    有兩種方法,一種是通過容器,一種是通過鏡像 1 首先使用 docker ps -a 查看本機上的所有容器 2 導出鏡像 使用 docker export 命令根據(jù)容器 id 將鏡像導成一個文件 上面命令執(zhí)行之后,我們便可以通過 ls 命令在當前目錄下發(fā)現(xiàn) image.tar 3 導入鏡像 使用 docker import 命令將這個鏡像導

    2024年02月03日
    瀏覽(23)
  • Docker容器------鏡像,容器基礎命令

    Docker容器------鏡像,容器基礎命令

    目錄 ?一,docker鏡像 ?1,查看docker版本 ?2,獲取鏡像 2.1查看下載到本地的所有鏡像? ?2.2 獲取鏡像信息 2.3 添加鏡像標簽(上傳鏡像到倉庫)? ?2.4 鏡像導出 ?2.5 鏡像導入 ?2.6 ,刪除鏡像 ?2.7 上傳鏡像 ?編輯?二,docker 容器操作 1,查看容器 2,容器創(chuàng)建----docker create ?

    2024年02月05日
    瀏覽(31)
  • 【Docker系列】容器基礎、Docker鏡像管理

    個人名片: 對人間的熱愛與歌頌,可抵歲月冗長?? Github???????:念舒_C.ying CSDN主頁??:念舒_C.ying 個人博客?? :念舒_C.ying 2.1 Docker鏡像查找 命令查找 docker官網(wǎng)查找 2.2 Docker鏡像管理 拉取MySQL鏡像 查看本地鏡像 鏡像加速(阿里云) Daocloud鏡像站加速 鏡像刪除 2.3 容器

    2024年01月25日
    瀏覽(23)
  • docker 鏡像/容器常用操作

    目錄 1、docker 下載鏡像 2、刪除鏡像 3、新建容器并啟動(測試) 4、列出所有正在運行的容器 5、刪除容器 6、啟動和停止容器 7、查看日志 8、查看元數(shù)據(jù)(詳細數(shù)據(jù)) 9、將容器中的文件拷貝到主機中 10、進入容器 11、容器之間數(shù)據(jù)同步 官方文檔:docker指令 1、docker 下載鏡像 2、

    2024年02月05日
    瀏覽(23)
  • Docker刪除鏡像和容器

    Docker刪除鏡像和容器

    首先需要停止所有的容器(只停止單個時把后面的變量改為image id即可) docker stop $(docker ps -a -q) 刪除所有的容器(只刪除單個時把后面的變量改為image id即可) docker rm $(docker ps -a -q) 查看host中的鏡像 docker images 刪除指定id的鏡像 docker rmi 想要刪除untagged images,也就是那些id為

    2024年02月16日
    瀏覽(25)
  • docker 打包鏡像或容器

    因為某臺服務器需要部署Tomcat,但是該服務武器不能連接外網(wǎng),所以需要先pull拉一下鏡像包,如果已經(jīng)有了現(xiàn)有的鏡像就不需要拉取了,直接從第二部開始就行。 具體操作步驟如下: 使用到的命令: docker commit :從容器創(chuàng)建一個新的鏡像 OPTIONS說明: -a :提交的鏡像作者; -c

    2024年02月02日
    瀏覽(26)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包