X86架构下,docker模拟ARMv8架构

X86架构下,docker模拟ARMv8架构

一、docker获取arm架构centos镜像,构建镜像

执行docker pull centos:7.9.2009 --platform=arm64,获取arm64架构版本centos7.9镜像

##拉取arm64架构版本centos7.9镜像
# docker pull centos:7.9.2009 --platform=arm64
7.9.2009: Pulling from library/centos
6717b8ec66cd: 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,查看镜像版本信息

debian# docker inspect centos:7.9.2009
[
    {
        "Id": "sha256:c9a1fdca3387618f8634949de4533419327736e2f5c618e3bfebe877aa331352",
        "RepoTags": [
            "centos:7.9.2009"
        ],
        "RepoDigests": [
            "centos@sha256:be65f488b7764ad3638f236b7b515b3678369a5124c47b8d32916d6487418ea4"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2022-02-14T19:39:38.447986786Z",
        "Container": "c464b3d55122c0cf4dcd0642de8ea207db58d2f94e5085c800390880a55d366e",
        "ContainerConfig": {
            "Hostname": "c464b3d55122",
            "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:d9f58c958f32b230d97b07531f8df29b2e70d1ba8cb6d2c484032f851de0308f",
            "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:d9f58c958f32b230d97b07531f8df29b2e70d1ba8cb6d2c484032f851de0308f",
            "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": "arm64",
        "Variant": "v8",
        "Os": "linux",
        "Size": 300707159,
        "VirtualSize": 300707159,
        "GraphDriver": {
            "Data": {
                "MergedDir": "/var/lib/docker/overlay2/0dee40fd225c743ac6edcac7b44efac308ab49e0638d1f5b290ab02366f90746/merged",
                "UpperDir": "/var/lib/docker/overlay2/0dee40fd225c743ac6edcac7b44efac308ab49e0638d1f5b290ab02366f90746/diff",
                "WorkDir": "/var/lib/docker/overlay2/0dee40fd225c743ac6edcac7b44efac308ab49e0638d1f5b290ab02366f90746/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:65f23ff12f4df9625427d229db82655bdadd805108d3431520673d79198419ff"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]

二、安装QEMU

下载qemu-aarch64-static.tar.gz

##获取qemu-arrch64架构压缩包
# wget https://github.com/multiarch/qemu-user-static/releases/download/v5.1.0-2/qemu-aarch64-static.tar.gz
# tar -zxvf qemu-aarch64-static.tar.gz
qemu-aarch64-static
# mv qemu-aarch64-static /usr/bin

拉取qemu-user-static镜像

##拉取qemu-user-static镜像
# docker pull multiarch/qemu-user-static:register

启动qemu

# docker run --rm --privileged multiarch/qemu-user-static:register
Setting /usr/bin/qemu-alpha-static as binfmt interpreter for alpha
Setting /usr/bin/qemu-arm-static as binfmt interpreter for arm
Setting /usr/bin/qemu-armeb-static as binfmt interpreter for armeb
Setting /usr/bin/qemu-sparc-static as binfmt interpreter for sparc
Setting /usr/bin/qemu-sparc32plus-static as binfmt interpreter for sparc32plus
Setting /usr/bin/qemu-sparc64-static as binfmt interpreter for sparc64
Setting /usr/bin/qemu-ppc-static as binfmt interpreter for ppc
Setting /usr/bin/qemu-ppc64-static as binfmt interpreter for ppc64
Setting /usr/bin/qemu-ppc64le-static as binfmt interpreter for ppc64le
Setting /usr/bin/qemu-m68k-static as binfmt interpreter for m68k
Setting /usr/bin/qemu-mips-static as binfmt interpreter for mips
Setting /usr/bin/qemu-mipsel-static as binfmt interpreter for mipsel
Setting /usr/bin/qemu-mipsn32-static as binfmt interpreter for mipsn32
Setting /usr/bin/qemu-mipsn32el-static as binfmt interpreter for mipsn32el
Setting /usr/bin/qemu-mips64-static as binfmt interpreter for mips64
Setting /usr/bin/qemu-mips64el-static as binfmt interpreter for mips64el
Setting /usr/bin/qemu-sh4-static as binfmt interpreter for sh4
Setting /usr/bin/qemu-sh4eb-static as binfmt interpreter for sh4eb
Setting /usr/bin/qemu-s390x-static as binfmt interpreter for s390x
Setting /usr/bin/qemu-aarch64-static as binfmt interpreter for aarch64
Setting /usr/bin/qemu-aarch64_be-static as binfmt interpreter for aarch64_be
Setting /usr/bin/qemu-hppa-static as binfmt interpreter for hppa
Setting /usr/bin/qemu-riscv32-static as binfmt interpreter for riscv32
Setting /usr/bin/qemu-riscv64-static as binfmt interpreter for riscv64
Setting /usr/bin/qemu-xtensa-static as binfmt interpreter for xtensa
Setting /usr/bin/qemu-xtensaeb-static as binfmt interpreter for xtensaeb
Setting /usr/bin/qemu-microblaze-static as binfmt interpreter for microblaze
Setting /usr/bin/qemu-microblazeel-static as binfmt interpreter for microblazeel
Setting /usr/bin/qemu-or1k-static as binfmt interpreter for or1k
Setting /usr/bin/qemu-hexagon-static as binfmt interpreter for hexagon

运行ARM架构centos容器

##查看当前docker内镜像信息
# docker images
REPOSITORY                   TAG        IMAGE ID       CREATED         SIZE
multiarch/qemu-user-static   register   4a73e8b061ed   2 months ago    4.9MB
centos                       7.9.2009   c9a1fdca3387   13 months ago   301MB
##运行arm架构centos,末尾c9a1fdca3387为容器ID
# docker run -it -v /usr/bin/qemu-aarch64-static:/usr/bin/qemu-aarch64-static c9a1fdca3387
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
[root@cceff132dbca /]# uname -m  #运行后自动进入环境,检查架构可知为aarch64
aarch64
[root@cceff132dbca /]# exit #退出虚拟环境
exit
# uname -m
x86_64

你可能感兴趣的:(香橙派5,docker,架构,容器,arm)