使用image-syncer迁移镜像

使用image-syncer迁移镜像

github AliyunContainerService/image-syncer: Docker image synchronization tool for Docker Registry V2 based services (github.com)

当我们处理数量较少的镜像迁移任务时,使用命令行迁移就可以解决这个问题。但是实际生产中涉及到成千上百个镜像,几T的镜像仓库数据时,迁移过程就变得耗时很是漫长,甚至丢失数据。这时,我们可以使用该工具来同步。

使用用例

1
2
3
4
5
6
7
# 获得帮助信息
./image-syncer -h

# 设置配置文件为config.json,默认registry为registry.cn-beijing.aliyuncs.com
# 默认namespace为ruohe,并发数为6
./image-syncer --proc=6 --auth=./auth.json --images=./images.json --namespace=ruohe \
--registry=registry.cn-beijing.aliyuncs.com --retries=3

配置文件

认证信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# auth.json
{
// 认证字段,其中每个对象为一个registry的一个账号和
// 密码;通常,同步源需要具有pull以及访问tags权限,
// 同步目标需要拥有push以及创建仓库权限,如果没有提供,则默认匿名访问

"quay.io": { // 支持 "registry" 和 "registry/namespace"(v1.0.3之后的版本) 的形式,需要跟下面images中的registry(registry/namespace)对应
// images中被匹配到的的url会使用对应账号密码进行镜像同步, 优先匹配 "registry/namespace" 的形式
"username": "xxx", // 用户名,可选,(v1.3.1 之后支持)valuse 使用 "${env}" 或者 "$env" 类型的字符串可以引用环境变量
"password": "xxxxxxxxx", // 密码,可选,(v1.3.1 之后支持)valuse 使用 "${env}" 或者 "$env" 类型的字符串可以引用环境变量
"insecure": true // registry是否是http服务,如果是,insecure 字段需要为true,默认是false,可选,支持这个选项需要image-syncer版本 > v1.0.1
},
"registry.cn-beijing.aliyuncs.com": {
"username": "xxx",
"password": "xxxxxxxxx"
},
"registry.hub.docker.com": {
"username": "xxx",
"password": "xxxxxxxxxx"
},
"quay.io/coreos": {
"username": "abc",
"password": "xxxxxxxxx",
"insecure": true
}
}

镜像同步文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# images.json
{
// 同步镜像规则字段,其中条规则包括一个源仓库(键)和一个目标仓库(值)

// 同步的最大单位是仓库(repo),不支持通过一条规则同步整个namespace以及registry

// 源仓库和目标仓库的格式与docker pull/push命令使用的镜像url类似(registry/namespace/repository:tag)
// 源仓库和目标仓库(如果目标仓库不为空字符串)都至少包含registry/namespace/repository
// 源仓库字段不能为空,如果需要将一个源仓库同步到多个目标仓库需要配置多条规则
// 目标仓库名可以和源仓库名不同(tag也可以不同),此时同步功能类似于:docker pull + docker tag + docker push

"quay.io/coreos/kube-rbac-proxy": "quay.io/ruohe/kube-rbac-proxy",
"xxxx":"xxxxx",
"xxx/xxx/xx:tag1,tag2,tag3":"xxx/xxx/xx"

// 当源仓库字段中不包含tag时,表示将该仓库所有tag同步到目标仓库,此时目标仓库不能包含tag
// 当源仓库字段中包含tag时,表示只同步源仓库中的一个tag到目标仓库,如果目标仓库中不包含tag,则默认使用源tag
// 源仓库字段中的tag可以同时包含多个(比如"a/b/c:1,2,3"),tag之间通过","隔开,此时目标仓库不能包含tag,并且默认使用原来的tag

// 当目标仓库为空字符串时,会将源镜像同步到默认registry的默认namespace下,并且repo以及tag与源仓库相同,默认registry和默认namespace可以通过命令行参数以及环境变量配置,参考下面的描述
}

同样支持yaml格式的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# auth.yaml
quay.io:
username: xxx
password: xxxxxxxxx
insecure: true
registry.cn-beijing.aliyuncs.com:
username: xxx
password: xxxxxxxxx
registry.hub.docker.com:
username: xxx
password: xxxxxxxxxx
quay.io/coreos:
username: abc
password: xxxxxxxxx
insecure: true
---
# images.yaml
quay.io/coreos/kube-rbac-proxy: quay.io/ruohe/kube-rbac-proxy
quay.io/coreos/kube-rbac-proxy:v1.0: quay.io/ruohe/kube-rbac-proxy
quay.io/coreos/kube-rbac-proxy:v1.0,v2.0: quay.io/ruohe/kube-rbac-proxy

同步镜像

提前准备好auth.yaml和images.yaml

1
image-syncer --proc=30 --auth=auth.yaml --images=images.yaml --retries=3
打赏
  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • Copyrights © 2018-2024 Outsrkem
  • 访问人数: | 浏览次数:

      请我喝杯咖啡吧~

      支付宝
      微信