Registry Sync - Docker Image Synchronization Tool
1.1K
企业级 Docker/Harbor 镜像同步管理平台
轻松实现跨 Registry 镜像同步,支持多架构镜像、定时任务、实时通知
# 1. 下载 docker-compose.yml
curl -O https://raw.githubusercontent.com/yunzck8s/registry-sync/main/docker-compose.yml
# 2. 启动服务
docker-compose up -d
# 3. 访问 Web 界面
open http://localhost:8080
# 拉取镜像
docker pull zunshen/registry-sync:latest
# 运行容器
docker run -d \
--name registry-sync \
-p 8080:8080 \
-v ./data:/app/data \
-e TZ=Asia/Shanghai \
zunshen/registry-sync:latest
# 访问 Web 界面
open http://localhost:8080
# 部署到 K8s 集群
kubectl apply -k https://github.com/yunzck8s/registry-sync/k8s
# 查看服务状态
kubectl get pods -n registry-sync
docker-compose.yml
version: '3.8'
services:
registry-sync:
image: zunshen/registry-sync:latest
container_name: registry-sync
restart: unless-stopped
ports:
- "8080:8080"
volumes:
- ./data:/app/data
environment:
- TZ=Asia/Shanghai
healthcheck:
test: ["CMD", "wget", "--spider", "http://localhost:8080/api/v1/health"]
interval: 30s
timeout: 3s
retries: 3
docker-compose up -d
完整部署配置
# 1. 克隆仓库
git clone https://github.com/yunzck8s/registry-sync.git
cd registry-sync/k8s
# 2. 修改配置(可选)
# - 修改 ingress.yaml 中的域名
# - 修改 pvc.yaml 中的存储大小
# 3. 部署
kubectl apply -k .
# 4. 查看状态
kubectl get all -n registry-sync
# 5. 访问服务
# - ClusterIP: kubectl port-forward -n registry-sync svc/registry-sync 8080:8080
# - Ingress: https://your-domain.com
K8s 资源说明
资源限制
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "500m"
前置要求
步骤
# 1. 克隆代码
git clone https://github.com/yunzck8s/registry-sync.git
cd registry-sync
# 2. 构建前端
cd web
npm install
npm run build
# 3. 构建后端
cd ..
go build -o registry-sync-server ./cmd/server
# 4. 运行
./registry-sync-server --port 8080 --db data/registry-sync.db
Docker 镜像构建
# 构建镜像
docker build -t registry-sync:latest .
# 运行
docker run -d -p 8080:8080 -v ./data:/app/data registry-sync:latest
https://registry-1.docker.iohttps://harbor.example.comhttps://registry.cn-hangzhou.aliyuncs.com提示:
基础配置
源配置
目标配置
Tag 过滤规则
^1\.2[0-9]\..* 匹配 1.2x 版本.*-alpine,.*-debug 排除 alpine 和 debug 版本架构选择
定时任务设置
0 * * * *0 2 * * *0 12 * * *0 2 * * 10 2 1 * *0 */6 * * *0 */12 * * *通知配置
手动执行
停止执行
查看执行日志
添加企业微信通知
添加钉钉通知
通知消息格式
### 镜像同步任务通知
> 任务名称:同步 Nginx
> 执行状态:成功 / 失败
> 执行耗时:2分30秒
>
> 数据统计
> - 总计:16 个 blob
> - 成功:16 个
> - 跳过:0 个
2025-11-27 18:00:00
Tag 过滤示例
# 只同步 latest 和 stable 标签
包含:^(latest|stable)$
# 同步所有 1.x 版本
包含:^1\..*
# 排除所有 beta 和 rc 版本
排除:.*(beta|rc).*
# 只同步最新 10 个版本
保留最新:10
多架构镜像同步
系统会自动识别多架构镜像(Manifest List),并同步所有选中的架构:
整个项目同步
不填写源仓库名,系统会自动:
http://localhost:8080/api/v1application/json# 创建 Registry
POST /api/v1/registries
{
"name": "Harbor Prod",
"url": "https://harbor.example.com",
"username": "admin",
"password": "password",
"enabled": true
}
# 列出所有 Registry
GET /api/v1/registries
# 获取单个 Registry
GET /api/v1/registries/:id
# 更新 Registry
PUT /api/v1/registries/:id
# 删除 Registry
DELETE /api/v1/registries/:id
# 测试连接
POST /api/v1/registries/:id/test
# 列出项目
GET /api/v1/registries/:id/projects
# 列出仓库
GET /api/v1/registries/:id/projects/:project/repositories
# 创建任务
POST /api/v1/tasks
# 列出所有任务
GET /api/v1/tasks
# 获取任务详情
GET /api/v1/tasks/:id
# 更新任务
PUT /api/v1/tasks/:id
# 删除任务
DELETE /api/v1/tasks/:id
# 立即运行
POST /api/v1/tasks/:id/run
# 停止任务
POST /api/v1/tasks/:id/stop
# 列出执行记录
GET /api/v1/executions?limit=20&offset=0
# 获取执行详情
GET /api/v1/executions/:id
# 获取执行日志
GET /api/v1/executions/:id/logs
# 统计信息
GET /api/v1/stats
# 创建通知渠道
POST /api/v1/notifications
# 列出所有渠道
GET /api/v1/notifications
# 更新渠道
PUT /api/v1/notifications/:id
# 删除渠道
DELETE /api/v1/notifications/:id
# 测试发送
POST /api/v1/notifications/:id/test
# 连接 WebSocket(实时进度)
WS /api/v1/ws
# 消息格式
{
"type": "progress",
"execution_id": 1,
"data": {
"total_blobs": 100,
"synced_blobs": 50,
"progress": 50.0
}
}
# 健康检查
GET /api/v1/health
# 响应
{
"status": "ok",
"version": "1.0.0"
}
registry-sync/
├── cmd/
│ └── server/main.go # Web 服务器入口
├── internal/ # 内部包(Web 服务专用)
│ ├── api/handlers/ # REST API 处理器
│ ├── api/middleware/ # 中间件(CORS 等)
│ ├── db/models/ # 数据模型
│ ├── db/store/ # 数据访问层
│ ├── scheduler/ # 任务调度器
│ └── websocket/ # WebSocket Hub
├── pkg/ # 公共包
│ ├── registry/ # Registry API V2 客户端
│ ├── filter/ # Tag 过滤器
│ └── notification/ # 通知发送
├── web/ # React 前端
│ ├── src/
│ │ ├── api/ # API 客户端
│ │ ├── components/ # 通用组件
│ │ ├── pages/ # 页面组件
│ │ ├── hooks/ # 自定义 Hooks
│ │ └── types/ # TypeScript 类型
│ └── vite.config.ts
├── k8s/ # Kubernetes 部署配置
│ ├── namespace.yaml
│ ├── deployment.yaml
│ ├── service.yaml
│ ├── ingress.yaml
│ ├── pvc.yaml
│ └── kustomization.yaml
├── Dockerfile # Docker 镜像构建
├── docker-compose.yml # Docker Compose 配置
├── .github/workflows/ # GitHub Actions CI/CD
│ └── docker-build.yml
└── README.md
需求: 从 Docker Hub 迁移镜像到阿里云 ACR
配置:
需求: 从公网 Harbor 同步到内网 Harbor
配置:
需求: 生产镜像定期备份到备用 Registry
配置:
需求: 同步多架构镜像到多个区域
配置:
A: Docker Hub 有限流限制(免费用户 100次/6小时)
A: 系统不会自动创建项目
A: 检查以下几点:
A: 检查:
A:
proxy_set_header Upgrade $http_upgrade;A:
A:
最小权限原则
网络隔离
数据保护
密码管理
HTTPS
实际速度取决于网络带宽和 Registry 性能
欢迎提交 Issue 和 Pull Request!
开发流程:
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)开发规范:
gofmt 格式本项目采用 MIT License 开源协议
感谢以下开源项目:
Made with ❤️ for DevOps Engineers
⭐ 如果这个项目对你有帮助,请给个 Star!
Content type
Image
Digest
sha256:669ed0c0c…
Size
22.6 MB
Last updated
10 months ago
docker pull zunshen/registry-sync