x86 架构运行 其他架构镜像

初始环境

系统: centos 7 ( x86_64 GNU/Linux)
docker版本 :Docker version 20.10.11

1、初始化

  • binfmt_misc 、QEMU依赖安装
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  • 验证qemu是否安装成功
[root@VM-187-115-centos ~]# ls  /proc/sys/fs/binfmt_misc/ 
kshcomp          qemu-arm      qemu-m68k          qemu-mips64    qemu-mipsn32el  qemu-ppc64le  qemu-sh4          qemu-sparc64   status
qemu-aarch64     qemu-armeb    qemu-microblaze    qemu-mips64el  qemu-or1k       qemu-riscv32  qemu-sh4eb        qemu-xtensa
qemu-aarch64_be  qemu-hexagon  qemu-microblazeel  qemu-mipsel    qemu-ppc        qemu-riscv64  qemu-sparc        qemu-xtensaeb
qemu-alpha       qemu-hppa     qemu-mips          qemu-mipsn32   qemu-ppc64      qemu-s390x    qemu-sparc32plus  register

可以看到qemu支持的架构有 arm、mips ,qemu-mips64el的状态是 enabled

[root@VM-187-115-centos ~]# cat /proc/sys/fs/binfmt_misc/qemu-mips64el
enabled
interpreter /usr/bin/qemu-mips64el-static
flags: F
offset 0
magic 7f454c4602010100000000000000000002000800
mask ffffffffffffff00fffffffffffffffffeffffff

2、测试

1、 pull 一个mips64架构的镜像,验证是否可以运行
2、uname -a查看容器的架构类型

[root@VM-187-115-centos ~]# docker pull loongsongd/debian_mips64el_x64:v9
v9: Pulling from loongsongd/debian_mips64el_x64
46118084dfd4: Pull complete 
Digest: sha256:1356718d3a359d66cfa2b4560d64f57eaa0f3b3963d918d5c0ee23674018134a
Status: Downloaded newer image for loongsongd/debian_mips64el_x64:v9
docker.io/loongsongd/debian_mips64el_x64:v9
[root@VM-187-115-centos ~]# docker images
REPOSITORY                       TAG       IMAGE ID       CREATED        SIZE
loongsongd/debian_mips64el_x64   v9        f807eae237d5   6 days ago     267MB
multiarch/qemu-user-static       latest    871019ea8dda   3 months ago   299MB
[root@VM-187-115-centos ~]# docker run -it loongsongd/debian_mips64el_x64:v9 /bin/bash
root@620f1c5e8616:/# uname -a
Linux 620f1c5e8616 5.4.119-1-tlinux4-0008 #1 SMP Fri Nov 26 11:17:45 CST 2021 mips64 GNU/Linux

3、loongarch 架构的支持

默认qemu的配置中,是不支持 loongarch 架构的, 所以如果镜像的架构是 loongarch 的话,那需要另外注册。

1、下载 qemu-loongarch64-static,放到/usr/bin 目录

[root@VM-187-115-centos /data/workspace]# wget https://gitee.com/michael0066/qemu-loongarch64-static/blob/master/qemu-loongarch64-static

2、 注册 loongarch

[root@VM-187-115-centos /data/workspace]# echo ":qemu-loongarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02\x01:\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-loongarch64-static:" > /proc/sys/fs/binfmt_misc/register

//  检查是否注册成功
[root@VM-187-115-centos /data/workspace]# ls  /proc/sys/fs/binfmt_misc/ |grep loonqemu-loongarch64
qemu-loongarch64

3、 下载loongarch 镜像,确认是否可以运行(uname -a 查看系统架构

# docker pull loongsongd/debian10_loongarch64_x64:e15.0
[root@VM-187-115-centos /data/workspace]# docker images
REPOSITORY                                               TAG           IMAGE ID       CREATED        SIZE
loongsongd/debian_mips64el_x64                           v9            f807eae237d5   6 days ago     267MB
mirrors.tencent.com/wwlocal4ubuntu/ubuntu_arm_compiler   tag20220215   5fe79aae8948   2 weeks ago    3.67GB
loongsongd/debian10_loongarch64_x64                      e15.0         6e04cd1bee86   2 months ago   2.91GB
multiarch/qemu-user-static                               latest        871019ea8dda   3 months ago   299MB
[root@VM-187-115-centos /data/workspace]# docker run -it loongsongd/debian10_loongarch64_x64:e15.0 /bin/bash
root@44adb0d84b94:/# uname -a
Linux 44adb0d84b94 5.16.0 #1 SMP Fri Nov 26 11:17:45 CST 2021 loongarch64 loongarch64 loongarch64 GNU/Linux

4、可能遇到的问题

1、docker run 可能遇到的

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

解决方案:
这只是1个警告,不影响容器的运行。
可在镜像系统目录 /usr/bin 目录中放入 qemu-aarch64-static 文件,需要放对应架构的qemu-****-static 文件。

2、docker pull 被限制

Error response from daemon: toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit

解决方案:
登录一个dockerhub账号就就好了
docker login
然后按照提示输入用户名密码。

3、通过 tar 压缩linux系统制作的镜像,在跨平台运行的时候可能会提示各种错误。
具体错误可参考文章:
mips64 银河麒麟V10 制作docker镜像

参考文章
qemu-user-static
https://hub.docker.com/r/loongsongd/debian10_loongarch64_x64

你可能感兴趣的:(x86 架构运行 其他架构镜像)