[记录] 小鸡容器迁移 + 使用 Portainer + Renovate 实现 GitOps 让容器自动更新
前言
之前薅了某为云的 2c2g 鸡,一直吃着灰,反观我的另一台 1c1g 鸡跑了好几个服务,是时候迁移了,顺便也来试试传说中的 GitOps,做个步骤记录,欢迎佬们提提建议
迁移
首先在所有鸡上都安装上 docker
随后先是 Portainer 的迁移。
在旧机器上:
登录 Portainer Web 界面。
进入
Settings→Backup。选择
Download backup file。设置个密码(可选),点击
Download。你会得到一个.tar.gz文件。
在新机器上:
ssh 上去,拉起一个新的、空的 Portainer。
第一次访问登录页面时,不要创建新管理员,点击下方的
Restore from file。上传刚才下载的备份文件,然后配置都回来了
然后是 docker 的容器部分。首先确认卷名,找到你真正需要的数据卷
docker volume ls # 找到后停掉
docker stop <容器ID>
打包
sudo -i
# 进入 Docker 卷目录 cd /var/lib/docker/volumes/
# 把你需要迁移的卷打包
tar -czvf /root/migration.tar.gz gpt_load-data newapi-data sub-store_data
# 直接 scp 扔过去 # 这里我尝试了 Termius 的 SFTP,估计是走本机中转,速度只有几十 k
scp /root/migration.tar.gz root@<IP>:/var/lib/docker/volumes/
# 在另一台机子上 sudo -i
cd /var/lib/docker/volumes/
tar -xzvf migration.tar.gz
# 让 docker 认出来
docker volume create gpt_load-data
docker volume create newapi-data
docker volume create sub-store_data
仓库配置
你需要把你的所有 docker-compose 文件组织起来,初始化 Git 仓库里并上传,这里以上传到 GitHub 为例。
文件结构仅供参考:
│ renovate.json
│
├─ai
│ docker-compose.yml
│
├─cloudflare-imgbed
│ docker-compose.yml
│ wrangler.toml
│
├─network
│ │ docker-compose.yml
│ │
│ ├─conf
│ │ Caddyfile
│ │
│ └─site
├─nezha-dashboard
│ docker-compose.yml
│
├─portainer
│ docker-compose.yml
│
└─sub-store
docker-compose.yml
接下来所有的容器相关操作都来到 Portainer 里面进行。
Portainer 配置
去 Portainer 创建 stack,Build method 选择到仓库类型,照着填就行
注意,如果你的 compose 文件里还依赖于仓库里的其他文件,比如 .env,那么得把下图中最下面的 Enable relative path volumes 勾上,Portainer 会从你填写的目录里把你的整个仓库拉下来再执行 compose 命令。
Re-pull image 这里我没有测试未勾选的效果,Force redeployment 的效果是每次 Webhook 触发时都会让容器重新部署,我这里没有勾选。
然后我们来到 GitHub 仓库里,填入对应 Webhook 地址,Payload URL 填 Portainer 给的, Content type 两种都可以。
完成后点 Update 就可以了。如果你之前给 Portainer 配置过 ZeroTrust,测试不通可能是 cf 那里没有配置 bypass 策略,得加个策略放行一下。
Note
不出意外的话就可以了。
一些可能的报错
ErrorFailureCould not get the contents of the file '**/docker-compose.yml
检查 compose 文件是否有误,比如是否写了正确的镜像名
Renovate 配置
现在我们只是实现了代码即基础设施,上了一辆定制的电动车,但是不踩油门不动,每个镜像都要手动改镜像版本再 git push,太麻烦了。接下来我们将引入Renovate 机器人,实现自动更新镜像。
Warning我也没用过 WatchTower,几种方法也没有孰好孰坏之分,这里不展开讨论
首先我们来把机器人安装到我们的仓库里,直达链接。添加到新仓库后会跳转到新页面来配置。这里没有许可证,选第二个免费版。
下一步,选择 Scan and Alert,这样子就会自动提 PR 了。
配置完成会跳转到个人主页,这里还能看到对应仓库的每一次触发日志
等一会仓库会自动收到一条来自机器人的 PR,类似于下图:
这条 PR 里会列出你的所有 compose 文件以及更新提示,可以直接 Merge,也可以顺手直接用下面配置覆盖。合并之后会多出一个 Dependency Dashboard 的 issue,可以在这里进行快速操作。
关于 renovate 的配置,建议仔细阅读一遍官方文档,这里放几个可能会用到的
两条路
这里我让 Gemini 和 Claude 改了 2 份 renovate.json,第一份让机器人来管理合并的事,挂了快一周,实测小版本更新自动 commit 没有问题;第二份中 "platformAutomerge" 不填,默认为 true,托管给 GitHub 来管理自动合并。但是 GitHub 私人仓库的 AutoMerge 功能只对 Pro 用户开放,而且我死活调不出来,一个 PR 挂在那里一天了都没有触发自动合并,等一位大佬来帮我看看
作用是上游镜像推了个小更新,就自动 commit 掉,大版本更新提 PR 手动批准
可用配置
{ "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": [ "config:recommended" ], "timezone": "Asia/Shanghai", "schedule": ["at any time"], "platformAutomerge": false, "automergeSchedule": ["at any time"], "ignoreTests": true, "packageRules": [ { "matchDatasources": ["docker"], "matchUpdateTypes": ["minor", "patch", "digest"], "automerge": true, "automergeType": "branch", "groupName": "all non-major docker updates" }, { "matchDatasources": ["docker"], "matchUpdateTypes": ["major"], "automerge": false, "addLabels": ["major-update-warning"] } ] } [未成功] GitHub Pro 用户配置
需要打开仓库设置里的 Allow auto-merge:
在我这里未生效,仅供参考
{ "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": [ "config:recommended" ], "timezone": "Asia/Shanghai", "schedule": ["at any time"], "packageRules": [ { "matchDatasources": ["docker"], "matchUpdateTypes": ["minor", "patch", "digest"], "automerge": true, "groupName": "all non-major docker updates" }, { "matchDatasources": ["docker"], "matchUpdateTypes": ["major"], "automerge": false, "addLabels": ["major-update-warning"] } ] } 后记
修改完文件记得跑一下下方的检查命令:
npx --yes --package renovate -- renovate-config-validator renovate.json 实测 bunx 不可用:
"err": { "code": "MODULE_NOT_FOUND", 如果忘了也没关系,机器人会在 issue 里报错
要是没啥问题,机器人就能自动干活了:
![[记录] 小鸡容器迁移 + 使用 Portainer + Renovate 实现 GitOps 让容器自动更新1](https://xiaohack.oss-cn-zhangjiakou.aliyuncs.com/typecho/images/2026/01/14/20260114105720_69670610dd8af.png!mark)
![[记录] 小鸡容器迁移 + 使用 Portainer + Renovate 实现 GitOps 让容器自动更新2](https://xiaohack.oss-cn-zhangjiakou.aliyuncs.com/typecho/images/2026/01/14/20260114105723_6967061325d4b.png!mark)
![[记录] 小鸡容器迁移 + 使用 Portainer + Renovate 实现 GitOps 让容器自动更新3](https://xiaohack.oss-cn-zhangjiakou.aliyuncs.com/typecho/images/2026/01/14/20260114105725_6967061553785.png!mark)
![[记录] 小鸡容器迁移 + 使用 Portainer + Renovate 实现 GitOps 让容器自动更新4](https://xiaohack.oss-cn-zhangjiakou.aliyuncs.com/typecho/images/2026/01/14/20260114105727_696706176bdeb.png!mark)
![[记录] 小鸡容器迁移 + 使用 Portainer + Renovate 实现 GitOps 让容器自动更新5](https://xiaohack.oss-cn-zhangjiakou.aliyuncs.com/typecho/images/2026/01/14/20260114105729_696706198577a.png!mark)
![[记录] 小鸡容器迁移 + 使用 Portainer + Renovate 实现 GitOps 让容器自动更新6](https://xiaohack.oss-cn-zhangjiakou.aliyuncs.com/typecho/images/2026/01/14/20260114105738_696706223e720.png!mark)
![[记录] 小鸡容器迁移 + 使用 Portainer + Renovate 实现 GitOps 让容器自动更新7](https://xiaohack.oss-cn-zhangjiakou.aliyuncs.com/typecho/images/2026/01/14/20260114105741_69670625b47dc.png!mark)
![[记录] 小鸡容器迁移 + 使用 Portainer + Renovate 实现 GitOps 让容器自动更新8](https://xiaohack.oss-cn-zhangjiakou.aliyuncs.com/typecho/images/2026/01/14/20260114105744_69670628e675a.png!mark)
![[记录] 小鸡容器迁移 + 使用 Portainer + Renovate 实现 GitOps 让容器自动更新9](https://xiaohack.oss-cn-zhangjiakou.aliyuncs.com/typecho/images/2026/01/14/20260114105747_6967062b103e0.png!mark)
![[记录] 小鸡容器迁移 + 使用 Portainer + Renovate 实现 GitOps 让容器自动更新10](https://xiaohack.oss-cn-zhangjiakou.aliyuncs.com/typecho/images/2026/01/14/20260114105750_6967062e7783b.png!mark)
![[记录] 小鸡容器迁移 + 使用 Portainer + Renovate 实现 GitOps 让容器自动更新11](https://xiaohack.oss-cn-zhangjiakou.aliyuncs.com/typecho/images/2026/01/14/20260114105758_69670636b6fdc.png!mark)
![[记录] 小鸡容器迁移 + 使用 Portainer + Renovate 实现 GitOps 让容器自动更新12](https://xiaohack.oss-cn-zhangjiakou.aliyuncs.com/typecho/images/2026/01/14/20260114105800_69670638f2eca.png!mark)
![[记录] 小鸡容器迁移 + 使用 Portainer + Renovate 实现 GitOps 让容器自动更新13](https://xiaohack.oss-cn-zhangjiakou.aliyuncs.com/typecho/images/2026/01/14/20260114105803_6967063b71cf1.png!mark)
![[记录] 小鸡容器迁移 + 使用 Portainer + Renovate 实现 GitOps 让容器自动更新14](https://xiaohack.oss-cn-zhangjiakou.aliyuncs.com/typecho/images/2026/01/14/20260114105805_6967063d8bca5.png!mark)