
说明
如果通过本地代码构建镜像,可以使用buildx来构建更方便一点,但是如果已经存在于公共镜像仓库,不限于dockerhub,有一种很方便的方式把多架构镜像同步到本地镜像仓库,比如Harbor
以前的模式
先分别把一个镜像不同的版本分别Pull到本地,并修改tag避免覆盖
docker pull nginx:v1 --platform=linux/amd64
docker tag nginx:v1 192.168.0.100:5000/nginx:v1-amd64
docker pull nginx --platform=linux/arm64
docker tag nginx:v1 192.168.0.100:5000/nginx:v1-arm64分别将两种架构的镜像push到本地镜像仓库,如果本地镜像仓库没有使用https,需要配置daemon.json或者使用
docker push 192.168.0.100:5000/nginx:v1-amd64
docker push 192.168.0.100:5000/nginx:v1-arm64再通过manifest构建多架构镜像
docker manifest create --insecure 192.168.0.100:5000/nginx:v1 192.168.0.100:5000/nginx:v1-amd64 192.168.0.100:5000/nginx:v1-arm64打注解
docker manifest annotate 192.168.0.100:5000/nginx:v1 192.168.0.100:5000/nginx:v1-amd64 --os linux --arch amd64
docker manifest annotate 192.168.0.100:5000/nginx:v1 192.168.0.100:5000/nginx:v1-arm64 --os linux --arch arm64Push到本地镜像仓库
docker manifest push 192.168.0.100:5000/nginx:v1有些许繁琐
使用skopeo
只需要一条命令,如果本地镜像仓库没有使用https,加--dest-tls-verify=false,如果是本地是mac,加--override-os linux
skopeo --override-os linux copy --dest-creds=$username:$password --dest-tls-verify=false --multi-arch=all docker://docker.io/nginx:v1 docker://192.168.0.100:5000/nginx:v1