差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

下次修改
前次修改
tech:docker-upgrade [2024/07/24 18:10] – 建立 jonathantech:docker-upgrade [2025/12/25 15:57] (目前版本) – [使用 watchtower 自動更新 docker images] jonathan
行 1: 行 1:
 ====== 使用 watchtower 自動更新 docker images ====== ====== 使用 watchtower 自動更新 docker images ======
 +<note important> 
 +**Watchtower Docker API 版本不相容問題** 
 +  * 這問題已在 Watchtower GitHub 上被多人回報 
 +    * Issue #2122 - 77+ 人反應相同問題(2025年11月11日開立) 
 +    * Issue #2124, #2125, #2126 - 多個重複問題 
 +    * 官方專案狀態:已停止維護超過 2 年(最後更新:2023年) 
 +  * 內建的 Docker SDK 版本為 API 1.25(太舊) 
 +  * 當 Alpine 升級到 3.23 的 Docker 29 要求最低 API 1.44 就會出現異常  
 +  * 目前 Workaround 方式是改用 nickfedor fork 維護的 images 
 +  * 更新 docker-compose.yml 語法<cli> 
 +cp docker-compose.yml docker-compose.yml.backup && \ 
 +sed -i 's|containrrr/watchtower|nickfedor/watchtower|g' docker-compose.yml && \ 
 +docker-compose down watchtower && \ 
 +docker-compose up -d watchtower 
 +</cli> 
 +</note> 
 +==== 定期模式 ==== 
 +  * .env 檔加入 THE_HOST <cli> 
 +echo THE_HOST=`hostname` >> .env 
 +</cli>
   * 在 docker-compose.yml 內 services: 加入 watchtower: Exp <file>   * 在 docker-compose.yml 內 services: 加入 watchtower: Exp <file>
 services: services:
行 8: 行 27:
  
   watchtower:   watchtower:
-    image: containrrr/watchtower+    container_name: watchtower 
 +    #image: containrrr/watchtower 
 +    image: nickfedor/watchtower
     volumes:     volumes:
       - /var/run/docker.sock:/var/run/docker.sock       - /var/run/docker.sock:/var/run/docker.sock
     environment:     environment:
 +      - TZ=Asia/Taipei
       - WATCHTOWER_SCHEDULE=0 0 4 * * *  # 每天凌晨4點檢查更新       - WATCHTOWER_SCHEDULE=0 0 4 * * *  # 每天凌晨4點檢查更新
-      - WATCHTOWER_CLEANUP=true  # 清理舊的像 +      - WATCHTOWER_CLEANUP=true  # 清理舊的 
-      - WATCHTOWER_NOTIFICATIONS=slack  # 使用 Slack 通知 +      #- WATCHTOWER_NOTIFICATIONS_HOSTNAME=${THE_HOST} 
-      - SLACK_HOOK_URL=https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK+      #- WATCHTOWER_NOTIFICATIONS=shoutrrr  # 使用 Discord 通知 
 +      #- WATCHTOWER_NOTIFICATION_URL=discord://token@id 
 +      #- WATCHTOWER_NOTIFICATION_TITLE=Watchtower Update 
 +      #- WATCHTOWER_NOTIFICATIONS_LEVEL=info 
 +      #- WATCHTOWER_NOTIFICATIONS=slack  # 使用 Slack 通知 
 +      #- SLACK_HOOK_URL=https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK 
 +      #- WATCHTOWER_NOTIFICATIONS=email  # 使用 EMail 通知 
 +      #- [email protected] 
 +      #- [email protected] 
 +      #- WATCHTOWER_NOTIFICATION_EMAIL_SERVER=smtp.gmail.com 
 +      #- WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT=587 
 +      #- [email protected] 
 +      #- WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD=app_password 
 +      #- WATCHTOWER_NOTIFICATION_EMAIL_DELAY=2 
 +    labels: 
 +      - "com.centurylinklabs.watchtower.enable=true" 
 +    restart: unless-stopped 
 +</file> 
 +<note tip> 
 + 
 +  * **關於 WATCHTOWER_NOTIFICATION_URL 的設定** 
 +    * 假設您的 Discord webhook URL 是:<cli>https://discord.com/api/webhooks/123456789012345678/abcdefghijklmnopqrstuvwxyz1234567890</cli> 
 +    * 需要轉換為 Shoutrrr 格式:<cli>discord://abcdefghijklmnopqrstuvwxyz1234567890@123456789012345678</cli> 
 + 
 +</note> 
 +==== CLI 模式 ==== 
 +  * 直接執行 docker cli<cli> 
 +docker run --rm -v /var/run/docker.sock:/var/run/docker.sock nickfedor/watchtower --run-once 
 +</cli>或是<cli> 
 +docker compose run watchtower --run-once 
 +</cli> 
 + 
 +==== API 模式 ==== 
 +  * 參考 - https://containrrr.dev/watchtower/http-api-mode/ 
 +  * 如果不想定期檢查更新, 可以透過呼叫 API 方式進行檢查更新 
 +  * Exp. Listen Port:8383 , API-Token:mytoken-123456789 
 +  * docker-compose.yml<file> 
 +services: 
 +  watchtower: 
 +    container_name: watchtower 
 +    #image: containrrr/watchtower 
 +    image: nickfedor/watchtower 
 +    volumes: 
 +      - /var/run/docker.sock:/var/run/docker.sock 
 +    command: --http-api-update 
 +    environment: 
 +      - TZ=Asia/Taipei 
 +      - WATCHTOWER_HTTP_API_TOKEN=mytoken-123456789 
 +      - WATCHTOWER_CLEANUP=true 
 +      - WATCHTOWER_NOTIFICATIONS=email 
 +      - WATCHTOWER_NOTIFICATIONS_HOSTNAME=${THE_HOST} 
 +      - WATCHTOWER_NOTIFICATIONS_HOSTNAME=myserver 
 +      - [email protected] 
 +      - [email protected] 
 +      - WATCHTOWER_NOTIFICATION_EMAIL_SERVER=smtp.gmail.com 
 +      - WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT=587 
 +      - WATCHTOWER_NOTIFICATION_EMAIL_SERVER_USER=myaccountid 
 +      - WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD=mypassword 
 +      - WATCHTOWER_NOTIFICATION_EMAIL_DELAY=2
     labels:     labels:
       - "com.centurylinklabs.watchtower.enable=true"       - "com.centurylinklabs.watchtower.enable=true"
 +    ports:
 +      - 8383:8080
     restart: unless-stopped     restart: unless-stopped
-</file> +</file
 +    * 呼叫 API 方式<cli> 
 +curl -H "Authorization: Bearer mytoken-123456789" http://localhost:8383/v1/update 
 +</cli>
  
 ===== 參考網址 ===== ===== 參考網址 =====
   * https://claude.ai/   * https://claude.ai/
 +  * https://containrrr.dev/watchtower/
 +  * https://github.com/nicholas-fedor/watchtower/
  
 {{tag>docker auto-upgrade}} {{tag>docker auto-upgrade}}
  • tech/docker-upgrade.1721815841.txt.gz
  • 上一次變更: 2024/07/24 18:10
  • jonathan