顯示頁面舊版反向連結Fold/unfold all回到頁頂 本頁是唯讀的,您可以看到原始碼,但不能更動它。您如果覺得它不應被鎖上,請詢問管理員。 ====== 使用 watchtower 自動更新 docker images ====== ==== 定期模式 ==== * .env 檔加入 THE_HOST <cli> echo THE_HOST=`hostname` >> .env </cli> * 在 docker-compose.yml 內 services: 加入 watchtower: Exp <file> services: your-app: image: your-image:latest # 其他應用配置... watchtower: container_name: watchtower image: containrrr/watchtower volumes: - /var/run/docker.sock:/var/run/docker.sock environment: - TZ=Asia/Taipei - WATCHTOWER_SCHEDULE=0 0 4 * * * # 每天凌晨4點檢查更新 - WATCHTOWER_CLEANUP=true # 清理舊的映像檔 #- WATCHTOWER_NOTIFICATIONS=slack # 使用 Slack 通知 #- SLACK_HOOK_URL=https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK #- WATCHTOWER_NOTIFICATIONS=email # 使用 EMail 通知 #- WATCHTOWER_NOTIFICATIONS_HOSTNAME=${THE_HOST} #- WATCHTOWER_NOTIFICATION_EMAIL_FROM=fromaddress@gmail.com #- WATCHTOWER_NOTIFICATION_EMAIL_TO=toaddress@gmail.com #- WATCHTOWER_NOTIFICATION_EMAIL_SERVER=smtp.gmail.com #- WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT=587 #- WATCHTOWER_NOTIFICATION_EMAIL_SERVER_USER=fromaddress@gmail.com #- WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD=app_password #- WATCHTOWER_NOTIFICATION_EMAIL_DELAY=2 labels: - "com.centurylinklabs.watchtower.enable=true" restart: unless-stopped </file> ==== CLI 模式 ==== * 直接執行 docker cli<cli> docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/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 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 - WATCHTOWER_NOTIFICATION_EMAIL_FROM=tryweb@ichiayi.com - WATCHTOWER_NOTIFICATION_EMAIL_TO=tryweb@ichiayi.com - 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: - "com.centurylinklabs.watchtower.enable=true" ports: - 8383:8080 restart: unless-stopped </file> * 呼叫 API 方式<cli> curl -H "Authorization: Bearer mytoken-123456789" http://localhost:8383/v1/update </cli> ===== 參考網址 ===== * https://claude.ai/ * https://containrrr.dev/watchtower/ {{tag>docker auto-upgrade}} tech/docker-upgrade.txt 上一次變更: 2025/02/25 23:26由 jonathan