Docker:使用x86平台Docker 拉取 arm版镜像

参考文档

1 docker manifest 介绍

开启 docker manifest

1
sudo vim /etc/docker/daemon.json
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
{
    "registry-mirrors": [
        "http://hub-mirror.c.163.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://registry.docker-cn.com",
        "https://registry.hub.docker.com"
    ],
    "experimental": true,
    "iptables": false
}
1
2
#  重新加载服务的配置文件
systemctl daemon-reload
1
2
# 重启docker
systemctl restart docker
1
2
3
4
5
6
#测试manifest是否开启
docker manifest
#查看docker是否开启experimental功能
docker version 
docker system info

3. 拉取指定平台镜像

如上manifest实验功能开启后,可通过如下命令拉取其他CPU平台的镜像。

1
2
3
4
5
#X86平台docker拉取arm镜像
docker pull --platform=arm64 镜像名:版本

#示例
docker pull --platform=arm64 nginx:latest

–platform:该参数是用于拉取指定平台的镜像,也是实验性功能,在开启manifest功能后就会出现。通过该参数可以手动指定需要的CPU平台镜像,而不用自动去识别。

4. docker manifest 常用命令及操作

4.1 查看已有镜像的manifest

1
2
#查看已有镜像的manifest
docker manifest inspect --insecure nginx

4.2 创建manifest镜像信息

1
2
#创建manifest镜像信息
docker manifest create --insecure xxx/nginx:latest xxx/nginx:nginx-arm64 xxx/nginx:nginx-x86

–insecure :这个命令主要是防止你远程仓库没有Https证书的问题,最好加上

xxx/nginx:latest :统一架构后的镜像地址,可有可无

xxx/nginx:nginx-arm64 :已经在仓库中有的镜像地址

xxx/nginx:nginx-x86 :已经在仓库中有的镜像地址

如果不想新建manifest list镜像地址,而是想用已有的镜像地址,那么可以参考这个命令:

1
2
# 使用已有的镜像地址
docker manifest create --insecure --amend xxx/nginx:nginx-arm64 xxx/nginx:nginx-x86

–amend选项,将x86的架构信息增加到了arm64架构中。

4.3 提交manifest镜像信息

将这个manifest提交到仓库中

1
2
3
4
#将manifest镜像信息提交到仓库中
docker manifest push xxx/nginx:latest
#验证下镜像信息是否被提交
docker manifest inspect xxx/nginx:latest