我可以设置一个ARM64 Docker映像,但是可以运行任何东西

发布于 2025-02-03 10:59:29 字数 2160 浏览 3 评论 0原文

我有一个centos 7 x86_64虚拟机。我需要在Oracle Linux 8 ARM64 Docker容器中做一些事情。

我安装了Docker和Qemu:

$ sudo yum install -y yum-utils
$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo 
$ sudo yum install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin \
 qemu-system-arm qemu qemu-user qemu-kvm qemu-kvm-tools libvirt virt-install \
 libvirt-python libguestfs-tools-c

然后,我启动Docker并设置QEMU-USER静态:

$ sudo systemctl start docker
$ docker run --rm --privileged multiarch/qemu-user-static --reset

我的DockerFile是:

FROM oraclelinux:8.5
ENV container docker
RUN dnf -y install sssd nscd unzip zip xz which file
RUN useradd --uid 1001 -ms /bin/bash cm
RUN uname -m

然后使用以下内容创建X86_64和ARM64映像:

docker buildx create --name ol8_builder
docker buildx --builder ol8_builder build -t frickson/oracle8 . --platform=linux/amd64 --load --progress=plain
docker buildx --builder ol8_builder build -t frickson/oracle8arm . --platform=linux/arm64 --load --progress=plain

在两个图像上的构建过程中,run uneradd 工作和用户是创建的。 运行UNAME -M在两个系统上都可以使用,生成正确的输出(x86_64aarch64)。

X86_64机器工作正常:

$ docker run --rm --privileged frickson/oracle8 uname -m
x86_64

但是ARM64机器没有:

$ docker run --platform linux/arm64 --rm --privileged frickson/oracle8arm uname -a
exec /usr/bin/uname: no such file or directory

我猜它没有找到一个或多个库,因为它在图像构建过程中起作用。尝试运行任何命令(bashlstrue)都会在同一错误消息中导致。

有什么想法我缺少什么?谢谢!

编辑:回答 @josephsible-reinstatemonica:

它不起作用。而且我无法访问手臂主机来检查我的图像。

$ sudo docker run --platform linux/arm64 -it --rm --privileged oraclelinux:8 /bin/bash
Unable to find image 'oraclelinux:8' locally
8: Pulling from library/oraclelinux
e12ce518ed4b: Pull complete 
Digest: sha256:cad3a3dc2dd9f03dec02642dce1f194562e7f21820bc36ceb9f7b070d337fb45
Status: Downloaded newer image for oraclelinux:8
exec /bin/bash: no such file or directory

I have a CentOS 7 x86_64 virtual machine. I need to do some things in an Oracle Linux 8 arm64 docker container.

I installed docker and qemu:

$ sudo yum install -y yum-utils
$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo 
$ sudo yum install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin \
 qemu-system-arm qemu qemu-user qemu-kvm qemu-kvm-tools libvirt virt-install \
 libvirt-python libguestfs-tools-c

I then started docker and set up qemu-user-static:

$ sudo systemctl start docker
$ docker run --rm --privileged multiarch/qemu-user-static --reset

My Dockerfile is:

FROM oraclelinux:8.5
ENV container docker
RUN dnf -y install sssd nscd unzip zip xz which file
RUN useradd --uid 1001 -ms /bin/bash cm
RUN uname -m

Then created x86_64 and arm64 images using the following:

docker buildx create --name ol8_builder
docker buildx --builder ol8_builder build -t frickson/oracle8 . --platform=linux/amd64 --load --progress=plain
docker buildx --builder ol8_builder build -t frickson/oracle8arm . --platform=linux/arm64 --load --progress=plain

During the build on both images, the RUN useradd works and the user is created. The RUN uname -m works on both systems, producing the correct output (x86_64 and aarch64 respectively).

The x86_64 machine works correctly:

$ docker run --rm --privileged frickson/oracle8 uname -m
x86_64

But the arm64 machine does not:

$ docker run --platform linux/arm64 --rm --privileged frickson/oracle8arm uname -a
exec /usr/bin/uname: no such file or directory

I'm guessing it's not finding one or more libraries, since it worked during the image build. Trying to run any command (bash, ls, true) all result in the same error message.

Any ideas what I'm missing? Thanks!

EDIT: In response to @JosephSible-ReinstateMonica:

It didn't work. And I don't have access to an ARM host to check my image.

$ sudo docker run --platform linux/arm64 -it --rm --privileged oraclelinux:8 /bin/bash
Unable to find image 'oraclelinux:8' locally
8: Pulling from library/oraclelinux
e12ce518ed4b: Pull complete 
Digest: sha256:cad3a3dc2dd9f03dec02642dce1f194562e7f21820bc36ceb9f7b070d337fb45
Status: Downloaded newer image for oraclelinux:8
exec /bin/bash: no such file or directory

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦太阳 2025-02-10 10:59:29

当您运行docker运行-RM-私有的Multiarch/Qemu-user static -Reset时,它将Aarch64二进制文件的处理程序设置为:

[root@localhost ~]# cat /proc/sys/fs/binfmt_misc/qemu-aarch64
enabled
interpreter /usr/bin/qemu-aarch64-static
flags:
offset 0
magic 7f454c460201010000000000000000000200b700
mask ffffffffffffff00fffffffffffffffffeffffff

不幸的是,Centos 7没有没有- 静态这些二进制文件的版本:

[root@localhost ~]# ls /usr/bin/qemu-aarch64*
/usr/bin/qemu-aarch64

幸运的是,Multiarch/Qemu-user static容器在图像中包含必要的二进制文件;您可以像这样复制到主机上:

$ docker run --rm  --entrypoint tar multiarch/qemu-user-static \
    -C /usr/bin -cf- . | tar -C /usr/bin -xf-

现在我们有:

[root@localhost bin]# ls /usr/bin/qemu-aarch64*
/usr/bin/qemu-aarch64  /usr/bin/qemu-aarch64_be-static  /usr/bin/qemu-aarch64-static

这使我们如此接近,但是我们需要将静态二进制安装到图像中,如 for Multiarch/qemu-user static :(

[root@localhost bin]# docker run --platform linux/arm64 --rm -v /usr/bin/qemu-aarch64-static:/usr/bin/qemu-aarch64-static  oraclelinux:8.5 uname -a
Linux 2d7e2e0ce6d7 3.10.0-1160.66.1.el7.x86_64 #1 SMP Wed May 18 16:02:34 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux

或您需要将解释器构建到图像中。)

我们需要Mount QEMU-AARCH64静态在CentOS 7上的容器内部,因为内核似乎不支持f flag BINFMT_MISC解释器。 f标志意味着:

f-修复二进制

BINFMT_MISC的通常行为是在调用MISC格式文件时懒洋洋地产生二进制的行为。但是,面对安装命名空间和更换磁盘,这并不能很好地工作,因此F模式在安装仿真并使用打开的图像来产生仿真器后立即打开二进制文件,这意味着它始终安装后可以使用,不管环境如何变化。

(来自“ noreferrer”> kernel document

) Multiarch/Qemu-user static 如果您设置
- 在命令行上持续YES,但是在CentOS 7上失败了:

$ docker run --rm --privileged multiarch/qemu-user-static --reset
--persistent yes
...
Setting /usr/bin/qemu-aarch64-static as binfmt interpreter for aarch64
sh: write error: Invalid argument

使用最近的Fedora发行版(以及可能还有其他),您可以简单地安装QEMU-user static /code>软件包,一切都将工作(无需使用Multiarch/Qemu-user static image):

$ cat /etc/fedora-release
Fedora release 34 (Thirty Four)
$ rpm -q qemu-user-static
qemu-user-static-5.2.0-9.fc34.x86_64
$ uname -m
x86_64
$ docker run --platform linux/arm64 --rm oraclelinux:8.5 uname -a
Linux 6f04d17234f5 5.17.6-100.fc34.x86_64 #1 SMP PREEMPT Mon May 9 14:41:31 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux

qemu-user static软件包软件包安装所有<代码> binfmt_misc
给您的注册。

When you run docker run --rm --privileged multiarch/qemu-user-static --reset, it sets the handler for aarch64 binaries to:

[root@localhost ~]# cat /proc/sys/fs/binfmt_misc/qemu-aarch64
enabled
interpreter /usr/bin/qemu-aarch64-static
flags:
offset 0
magic 7f454c460201010000000000000000000200b700
mask ffffffffffffff00fffffffffffffffffeffffff

Unfortunately, CentOS 7 doesn't have the -static versions of these binaries:

[root@localhost ~]# ls /usr/bin/qemu-aarch64*
/usr/bin/qemu-aarch64

Fortunately, the multiarch/qemu-user-static container includes the necessary binaries in the image; you can copy onto your host like this:

$ docker run --rm  --entrypoint tar multiarch/qemu-user-static \
    -C /usr/bin -cf- . | tar -C /usr/bin -xf-

Now we have:

[root@localhost bin]# ls /usr/bin/qemu-aarch64*
/usr/bin/qemu-aarch64  /usr/bin/qemu-aarch64_be-static  /usr/bin/qemu-aarch64-static

This gets us so close, but we need to mount the static binary into the image as described in the docs for multiarch/qemu-user-static:

[root@localhost bin]# docker run --platform linux/arm64 --rm -v /usr/bin/qemu-aarch64-static:/usr/bin/qemu-aarch64-static  oraclelinux:8.5 uname -a
Linux 2d7e2e0ce6d7 3.10.0-1160.66.1.el7.x86_64 #1 SMP Wed May 18 16:02:34 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux

(Or you need to build the interpreter into the image.)

We need to mount qemu-aarch64-static inside the container on CentOS 7 because the kernel doesn't appear to support the F flag for binfmt_misc interpreters. The F flag means:

F - fix binary

The usual behaviour of binfmt_misc is to spawn the binary lazily when the misc format file is invoked. However, this doesn’t work very well in the face of mount namespaces and changeroots, so the F mode opens the binary as soon as the emulation is installed and uses the opened image to spawn the emulator, meaning it is always available once installed, regardless of how the environment changes.

(from the kernel documentation)

multiarch/qemu-user-static will set the F flag if you set
--persistent yes on the command line, but on CentOS 7 this fails with:

$ docker run --rm --privileged multiarch/qemu-user-static --reset
--persistent yes
...
Setting /usr/bin/qemu-aarch64-static as binfmt interpreter for aarch64
sh: write error: Invalid argument

With recent Fedora distributions (and probably others as well), you can simply install the qemu-user-static package and everything will Just Work (no need to use the multiarch/qemu-user-static image):

$ cat /etc/fedora-release
Fedora release 34 (Thirty Four)
$ rpm -q qemu-user-static
qemu-user-static-5.2.0-9.fc34.x86_64
$ uname -m
x86_64
$ docker run --platform linux/arm64 --rm oraclelinux:8.5 uname -a
Linux 6f04d17234f5 5.17.6-100.fc34.x86_64 #1 SMP PREEMPT Mon May 9 14:41:31 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux

The qemu-user-static package installs all the binfmt_misc
registrations for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文