x86 架構(gòu)運(yùn)行 其他架構(gòu)鏡像

初始環(huán)境

系統(tǒng): 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
  • 驗(yàn)證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支持的架構(gòu)有 arm、mips ,qemu-mips64el的狀態(tài)是 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、測(cè)試

1、 pull 一個(gè)mips64架構(gòu)的鏡像,驗(yàn)證是否可以運(yùn)行
2、uname -a查看容器的架構(gòu)類型

[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 架構(gòu)的支持

默認(rèn)qemu的配置中,是不支持 loongarch 架構(gòu)的, 所以如果鏡像的架構(gòu)是 loongarch 的話,那需要另外注冊(cè)。

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、 注冊(cè) 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

//  檢查是否注冊(cè)成功
[root@VM-187-115-centos /data/workspace]# ls  /proc/sys/fs/binfmt_misc/ |grep loonqemu-loongarch64
qemu-loongarch64

3、 下載loongarch 鏡像,確認(rèn)是否可以運(yùn)行(uname -a 查看系統(tǒng)架構(gòu)

# 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、可能遇到的問(wèn)題

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個(gè)警告,不影響容器的運(yùn)行。
可在鏡像系統(tǒng)目錄 /usr/bin 目錄中放入 qemu-aarch64-static 文件,需要放對(duì)應(yīng)架構(gòu)的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

解決方案:
登錄一個(gè)dockerhub賬號(hào)就就好了
docker login
然后按照提示輸入用戶名密碼。

3、通過(guò) tar 壓縮linux系統(tǒng)制作的鏡像,在跨平臺(tái)運(yùn)行的時(shí)候可能會(huì)提示各種錯(cuò)誤。
具體錯(cuò)誤可參考文章:
mips64 銀河麒麟V10 制作docker鏡像

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

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容