Contents

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

参考文档

1 docker manifest 介绍

  • docker manifest特性可支持用户在不同系统架构的机器上分别运行不同的架构的镜像。这一点基本不需要用户做任何适配,非常的方便。

  • manifest list是一个镜像清单列表,用于存放多个不同os/arch的镜像信息;主要用到manifest的目的,其实还是多用于存放不同的os/arch信息,也就是方便我们在不同的CPU架构(arm或者x86)或者操作系统中,通过一个镜像名称拉取对应架构或者操作系统的镜像, ( 这个尤其是在K8S中,对于异构CPU的服务器中的镜像显得尤为有效。)

  • 注:manifest文件仅仅是针对于已经在仓库中的镜像!!! 换句话说,就是这个镜像是刚从仓库中pull下来的!如果这个镜像是自己build的,需要先push到仓库中,否则,这个镜像是没有manifest文件的!!同样的,如果你pull了一个镜像,tag了一下,再去看这个manifest文件,也是没有的,因为tag后的镜像不在镜像仓库中。

开启 docker manifest

  • docker manifest是实验性功能,开启如下步骤
  • 1 修改配置文件
1
sudo vim /etc/docker/daemon.json
  • 添加一行配置"experimental": true,改行配置同时也会开启其他实验性功能,比如buildx,配置文件参考如下:
 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
}
  • 注:registry-mirrors 必填项,没有的话重启docker时直接报错
  • 重加载服务配置并重启docker
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