cross-arch docker save images
2024-8-25 21:21:11 Author: dyrnq.com(查看原文) 阅读量:8 收藏

本文介绍几种跨平台导出docker镜像为tar包或者tar.gz包的方法。比如在x86_64(也就是amd64)的机器上导出arm64机器上所需要的镜像(或反之)。

docker

https://github.com/moby/moby

docker pull --platform linux/amd64 nginx:latest
docker save nginx:latest | gzip > nginx-amd64.tar.gz

docker pull --platform linux/arm64 nginx:latest
docker save nginx:latest | gzip > nginx-arm64.tar.gz

注意:此方法有弊端,在当前架构下拉取非当前架构的镜像会有提示,比如如下报错,需要切换回原有架构的镜像

WARNING: The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64/v3) and no specific platform was requested

skopeo

https://github.com/containers/skopeo

skopeo --version
skopeo version 1.16.0 commit: 88aad2e56b6bfcb5433450be60ff0a1cc89fcc31
export https_proxy=http://192.168.8.88:8888;
skopeo \
--override-arch amd64 \
--override-os linux \
copy \
--additional-tag "nginx:latest" \
docker://docker.io/library/nginx:latest \
docker-archive:/tmp/nginx-amd64.tar
gzip   --keep --force --verbose /tmp/nginx-amd64.tar

export https_proxy=http://192.168.8.88:8888;
skopeo \
--override-arch arm64 \
--override-os linux \
copy \
--additional-tag "nginx:latest" \
docker://docker.io/library/nginx:latest \
docker-archive:/tmp/nginx-arm64.tar
gzip   --keep --force --verbose /tmp/nginx-arm64.tar

regclient

https://github.com/regclient/regclient

regctl version
VCSTag:     v0.7.0
VCSRef:     3e517a07d79f8a863cf39b78934935cdcb35f65f
VCSCommit:  3e517a07d79f8a863cf39b78934935cdcb35f65f
VCSState:   clean
VCSDate:    2024-07-12T18:40:58Z
Platform:   linux/amd64
GoVer:      go1.22.5
GoCompiler: gc
export https_proxy=http://192.168.8.88:8888;
regctl image export \
--verbosity debug \
--compress \
--name "nginx:latest" \
--platform "linux/amd64" nginx:latest nginx-amd64.tar.gz

export https_proxy=http://192.168.8.88:8888;
regctl image export \
--verbosity debug \
--compress \
--name "nginx:latest" \
--platform "linux/arm64" nginx:latest nginx-arm64.tar.gz

crane

https://github.com/google/go-containerregistry

crane pull --platform linux/arm64 debian:9 /tmp/debian-9-arm64.tar
docker load -i /tmp/debian-9-arm64.tar

文章来源: https://dyrnq.com/cross-arch-docker-save-images/
如有侵权请联系:admin#unsafe.sh