Watchtower + pushplus:容器更新推到微信
效果:Watchtower 拉到新镜像并重启容器后,通过 shoutrrr 通用 Webhook 通知微信。对方若 POST 自己的报文,查询参数里的
title/content仍然生效。
前置条件
- 一个 pushplus token(官网扫码获取)
- 正在使用 containrrr/watchtower(或兼容的 shoutrrr 通知)
配置步骤
方式一:shoutrrr generic(推荐)
Watchtower 用环境变量开通知。URL 请加引号,避免 & 被 shell 截断:
environment:
WATCHTOWER_NOTIFICATIONS: shoutrrr
WATCHTOWER_NOTIFICATION_URL: "generic+https://www.pushplus.plus/send?token=你的token&title=Watchtower&content=有容器更新请查看日志"
等价命令行:
-e WATCHTOWER_NOTIFICATIONS=shoutrrr \
-e WATCHTOWER_NOTIFICATION_URL="generic+https://www.pushplus.plus/send?token=你的token&title=Watchtower&content=有容器更新请查看日志"
若你的 shoutrrr 版本支持把正文打成 JSON,并可指定字段名,可让 title / content 带上本次更新摘要(template=json 是 shoutrrr 的 body 格式,token 继续放在查询参数):
generic+https://www.pushplus.plus/send?token=你的token&contenttype=application/json&template=json&titlekey=title&messagekey=content
参数以 shoutrrr generic 为准。不支持就不配,退回上面的 GET 查询参数。
方式二:命令结束后 curl
没有 shoutrrr、或 generic 发不出去时,用 --run-once 外包一层:
#!/bin/sh
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower --run-once
curl -s -X POST "https://www.pushplus.plus/send" \
-H "Content-Type: application/json" \
-d "{\"token\":\"$PUSHPLUS_TOKEN\",\"title\":\"Watchtower\",\"content\":\"本轮更新检查已结束\",\"template\":\"txt\"}"
验证
curl -X POST "https://www.pushplus.plus/send" \
-H "Content-Type: application/json" \
-d '{"token":"你的token","title":"Watchtower 配置测试","content":"token 可用","template":"markdown"}'
返回 JSON 的 code 为 200 后,再执行一次 --run-once 或等下一轮巡检。
常见问题
环境变量里 URL 被截断? & 必须放在引号内。compose 用 YAML 字符串,不要拆成多条未加引号的 -e。
每次检查都推、其实没更新? 看 Watchtower 是否「无更新也通知」。能关则只在实际更新时发;或改用方式二,自己判断退出后再决定是否 curl。
generic JSON 的字段对不上? 第三方 body 不会自动映射。确认 titlekey=title、messagekey=content,或改回查询参数固定文案。