ARMv8架构下,docker模拟X86架构
ARMv8架构下,docker模拟X86架构
一、docker获取arm架构centos镜像,构建镜像
执行docker pull centos:7.9.2009 --platform=arm64,获取arm64架构版本centos7.9镜像
##拉取arm64架构版本centos7.9镜像
orangepi@orangepi5:~$ docker pull centos:7.9.2009 --platform=x86
Error response from daemon: "x86": unknown operating system or architecture: invalid argument
orangepi@orangepi5:~$ docker pull centos:7.9.2009 --platform=x86-64
7.9.2009: Pulling from library/centos
2d473b07cdd5: Pull complete
Digest: sha256:be65f488b7764ad3638f236b7b515b3678369a5124c47b8d32916d6487418ea4
Status: Downloaded newer image for centos:7.9.2009
docker.io/library/centos:7.9.2009
执行docker inspect centos:7.9.2009,查看镜像版本信息
orangepi@orangepi5:~$ docker inspect centos:7.9.2009
[
{
"Id": "sha256:eeb6ee3f44bd0b5103bb561b4c16bcb82328cfe5809ab675bb17ab3a16c517c9",
"RepoTags": [
"centos:7.9.2009"
],
"RepoDigests": [
"centos@sha256:be65f488b7764ad3638f236b7b515b3678369a5124c47b8d32916d6487418ea4"
],
"Parent": "",
"Comment": "",
"Created": "2021-09-15T18:20:23.99863383Z",
"Container": "5e4c7bfd35862166e9efd7532208300600114f0acff8f82fd537a57bdd523fe2",
"ContainerConfig": {
"Hostname": "5e4c7bfd3586",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD ["/bin/bash"]"
],
"Image": "sha256:ba35a4b787c8f11e3b6ed9248c7663b4f27459e9715a1ace09f966259d5ebc3a",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"org.label-schema.build-date": "20201113",
"org.label-schema.license": "GPLv2",
"org.label-schema.name": "CentOS Base Image",
"org.label-schema.schema-version": "1.0",
"org.label-schema.vendor": "CentOS",
"org.opencontainers.image.created": "2020-11-13 00:00:00+00:00",
"org.opencontainers.image.licenses": "GPL-2.0-only",
"org.opencontainers.image.title": "CentOS Base Image",
"org.opencontainers.image.vendor": "CentOS"
}
},
"DockerVersion": "20.10.7",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/bash"
],
"Image": "sha256:ba35a4b787c8f11e3b6ed9248c7663b4f27459e9715a1ace09f966259d5ebc3a",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"org.label-schema.build-date": "20201113",
"org.label-schema.license": "GPLv2",
"org.label-schema.name": "CentOS Base Image",
"org.label-schema.schema-version": "1.0",
"org.label-schema.vendor": "CentOS",
"org.opencontainers.image.created": "2020-11-13 00:00:00+00:00",
"org.opencontainers.image.licenses": "GPL-2.0-only",
"org.opencontainers.image.title": "CentOS Base Image",
"org.opencontainers.image.vendor": "CentOS"
}
},
"Architecture": "amd64",
"Os": "linux",
"Size": 203936249,
"VirtualSize": 203936249,
"GraphDriver": {
"Data": {
"MergedDir": "/var/lib/docker/overlay2/bec7f1a9a08e909d2c915524405b9c830ad31f85a054bff3f484e176e9d969ce/merged",
"UpperDir": "/var/lib/docker/overlay2/bec7f1a9a08e909d2c915524405b9c830ad31f85a054bff3f484e176e9d969ce/diff",
"WorkDir": "/var/lib/docker/overlay2/bec7f1a9a08e909d2c915524405b9c830ad31f85a054bff3f484e176e9d969ce/work"
},
"Name": "overlay2"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:174f5685490326fc0a1c0f5570b8663732189b327007e47ff13d2ca59673db02"
]
},
"Metadata": {
"LastTagTime": "0001-01-01T00:00:00Z"
}
}
]
二、安装QEMU
下载qemu-aarch64-static.tar.gz
#安装qemu-user-static
orangepi@orangepi5:~$ sudo apt-get install qemu binfmt-support qemu-user-static
运行X86_64架构centos容器
```shell
##查看当前docker内镜像信息
orangepi@orangepi5:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hectormolinero/qemu-user-static latest 6db061469b82 11 months ago 63.7MB
1995chen/dnf centos6-2.0.2 b3548d6b4cd3 14 months ago 1.2GB
centos 7.9.2009 eeb6ee3f44bd 18 months ago 204MB
##运行X86架构centos,末尾eeb6ee3f44bd为容器ID
orangepi@orangepi5:~$ docker run -it -v /usr/bin/qemu-aarch64-static:/usr/bin/qemu-aarch64-static eeb6ee3f44bd
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
[root@f7c2b08e2825 /]# uname -m #运行后自动进入环境,检查架构可知为x86_64
x86_64
[root@f7c2b08e2825 /]# exit #退出虚拟环境
exit
orangepi@orangepi5:~$ uname -m
aarch64