由于 libc-bin 分段错误,无法为 arm64 构建 Dockerfile

由于 libc-bin 分段错误,无法为 arm64 构建 Dockerfile

尝试为该平台构建 Dockerfile 时出现以下错误linux/arm64

#5 58.06 Processing triggers for libc-bin (2.31-11) ...
#5 58.12 qemu: uncaught target signal 11 (Segmentation fault) - core dumped
#5 58.33 Segmentation fault (core dumped)
#5 58.35 qemu: uncaught target signal 11 (Segmentation fault) - core dumped
#5 58.69 Segmentation fault (core dumped)
#5 58.70 dpkg: error processing package libc-bin (--configure):
#5 58.70  installed libc-bin package post-installation script subprocess returned error exit status 139
#5 58.70 Processing triggers for ca-certificates (20210119) ...
#5 58.87 Updating certificates in /etc/ssl/certs...
#5 71.86 0 added, 0 removed; done.
#5 71.86 Running hooks in /etc/ca-certificates/update.d...
#5 71.89 done.
#5 71.98 Errors were encountered while processing:
#5 71.98  libc-bin
#5 72.06 E: Sub-process /usr/bin/dpkg returned an error code (1)

我已将 Dockerfile 修剪为以下内容:

FROM kalilinux/kali-rolling
ARG DEBIAN_FRONTEND=noninteractive
ARG TARGETPLATFORM
RUN apt update && \
    apt install wget -y

解决方案尝试 #1

我想到的第一件事是:https://stackoverflow.com/questions/59139453/repository-is-not-signed-in-docker-build/66215465#66215465。我在 ARM 32 位处理器上安装东西时遇到了这个问题,所以我尝试将相同的依赖项添加到此 Dockerfile 中,但没有成功。这些依赖项是:

但问题仍然存在。

解决方案尝试 #2

我遇到了https://github.com/docker/for-linux/issues/1131并尝试附加-o APT::Immediate-Configure=0以获取我的apt install命令,但这也不起作用。

解决方案尝试 #3

接下来,我遇到了这个答案:https://askubuntu.com/a/1035226/269349。当我将 Dockerfile 修改为如下所示时:

FROM kalilinux/kali-rolling
ARG DEBIAN_FRONTEND=noninteractive
ARG TARGETPLATFORM
RUN apt update && \
  rm /var/cache/ldconfig/aux-cache && \
  /sbin/ldconfig && \
  apt install wget -y -o APT::Immediate-Configure=0

我开始收到的下一个错误是:

 => ERROR [2/2] RUN apt update &&   rm /var/cache/ldconfig/aux-cache &&   /sbin/ldconfig &&   apt install wget -y -o APT::Immediate-Configure=0                                                                                                                                                                                                                       77.8s
------
 > [2/2] RUN apt update &&   rm /var/cache/ldconfig/aux-cache &&   /sbin/ldconfig &&   apt install wget -y -o APT::Immediate-Configure=0:
#5 0.203
#5 0.204 WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
#5 0.205
#5 1.055 Get:1 http://mirrors.jevincanders.net/kali kali-rolling InRelease [30.5 kB]
#5 3.496 Get:2 http://mirrors.jevincanders.net/kali kali-rolling/non-free arm64 Packages [157 kB]
#5 4.211 Get:3 http://mirrors.jevincanders.net/kali kali-rolling/main arm64 Packages [17.5 MB]
#5 67.37 Get:4 http://mirrors.jevincanders.net/kali kali-rolling/contrib arm64 Packages [87.3 kB]
#5 71.57 Fetched 17.8 MB in 1min 11s (249 kB/s)
#5 71.57 Reading package lists...
#5 76.73 Building dependency tree...
#5 77.44 Reading state information...
#5 77.51 4 packages can be upgraded. Run 'apt list --upgradable' to see them.
#5 77.55 qemu: uncaught target signal 11 (Segmentation fault) - core dumped
#5 77.74 Segmentation fault (core dumped)
------
Dockerfile:4
--------------------
   3 |     ARG TARGETPLATFORM
   4 | >>> RUN apt update && \
   5 | >>>   rm /var/cache/ldconfig/aux-cache && \
   6 | >>>   /sbin/ldconfig && \
   7 | >>>   apt install wget -y -o APT::Immediate-Configure=0
   8 |
--------------------

解决方案尝试 #4

我尝试了上一个答案(重新安装 libc-bin)下面的答案,但遇到了这个问题:

#4 25.05 Get:1 http://mirrors.jevincanders.net/kali kali-rolling/main arm64 libc-bin arm64 2.31-11 [735 kB]
#4 27.93 debconf: delaying package configuration, since apt-utils is not installed
#4 28.12 Fetched 735 kB in 2s (295 kB/s)
(Reading database ... 6748 files and directories currently installed.)
#4 28.30 Preparing to unpack .../libc-bin_2.31-11_arm64.deb ...
#4 28.32 Unpacking libc-bin (2.31-11) over (2.31-11) ...
#4 28.84 Setting up libc-bin (2.31-11) ...
#4 28.98 qemu: uncaught target signal 11 (Segmentation fault) - core dumped
#4 29.20 Segmentation fault (core dumped)
#4 29.22 qemu: uncaught target signal 11 (Segmentation fault) - core dumped
#4 29.42 Segmentation fault (core dumped)
#4 29.42 dpkg: error processing package libc-bin (--configure):
#4 29.42  installed libc-bin package post-installation script subprocess returned error exit status 139
#4 29.43 Errors were encountered while processing:
#4 29.43  libc-bin
#4 29.51 E: Sub-process /usr/bin/dpkg returned an error code (1)

这是我正在运行的命令:docker buildx build --platform linux/arm64 .

任何帮助将不胜感激。

答案1

内核版本和 qemu 版本的某些组合之间似乎存在一些问题。

更多信息请访问docker buildx GitHub 仓库

那里有一条评论解决了我的问题,那就是:

$ docker pull tonistiigi/binfmt:latest
$ docker run --privileged --rm tonistiigi/binfmt --uninstall qemu-*
$ docker run --privileged --rm tonistiigi/binfmt --install all)

不要跳过这个--uninstall步骤!

这个步骤解决了我的问题,它似乎与问题描述的问题相符。

答案2

根据这个错误报告,这似乎是内核的一个错误,应该通过将内核更新到最新版本来解决:https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/1928075

我可以在 GitLab CI 中重现这个错误,而且似乎只有架构arm64会触发该错误。armhf这样就好了:https://gitlab.com/arnaudr/test-binfmt-misc/-/pipelines/356065926/builds

答案3

我在 Ubuntu 20.04 上通过升级到最新的 qemu 5 解决了这个问题

sudo add-apt-repository ppa:jacob/virtualisation (for Ubuntu 20.04)
sudo apt-get update && sudo apt-get install qemu qemu-user qemu-user-static

答案4

我在 AMD 虚拟机上使用 QEMU 运行 ARM 模拟时发生了此错误。

这是一个对我有用的示例命令

FROM php:7.4

# See also https://forums.linuxmint.com/viewtopic.php?p=1871690
RUN apt-get update && \
  apt-get install -y libc-bin && \
  apt-get update && \
  apt-get install -y --no-install-recommends mariadb-client git zip || true && \
  dpkg --purge --force-all libc-bin && \
  apt-get install -y --no-install-recommends mariadb-client git zip && \
  rm -rf /var/lib/apt/lists/*

相关内容