python - standard_init_linux.go :211:exec user process caused "no such file or directory" with alpine linux and python

标签 python docker alpine-linux dockerpy

我有一个目录,其中包含 docker 文件、一个 attack.py 和一个 requirements.txt。

使用它,我创建了以下 dockerfile:

FROM arm64v8/python:3.7-alpine

COPY qemu-arm-static /usr/bin

COPY ./ app-ids
WORKDIR /app-ids

RUN pip install --no-cache-dir -r requirements.txt

CMD["python","./attack.py"]

但是,pip 安装行抛出: standard_init_linux.go:211:exec 用户进程导致“没有这样的文件或目录”

我不知道为什么。使用 ls、pwd 等命令尝试对此进行调试会产生相同的错误。

谁能解释一下我做错了什么?

最佳答案

我猜您正在尝试在非 arm64v8 平台上构建 docker 镜像。对于其余的答案,我会假设。

提供的解决方案将特定于 Ubuntu 发行版(主机),但我想它在其他 linux 发行版上应该类似。

解决方案 1 [在 Ubuntu 18.04 上工作]

来自 https://github.com/docker/for-linux/issues/56我们可以看到目前在 Debian(以及 Ubuntu?)的软件包中存在错误。

sudo apt-get install qemu-user-static

git clone https://github.com/computermouth/qemu-static-conf.git
sudo mkdir -p /lib/binfmt.d
sudo cp qemu-static-conf/*.conf /lib/binfmt.d/
sudo systemctl restart systemd-binfmt.service

这将从解决方案 2 中删除 qemu-user-binfmt 方法。但是在该包中,提供的配置文件不在文件夹中,并且配置错误,供 systemd- 使用binfmt.

此外,我们从 git 存储库获取配置文件并将它们放在 systemd-binfmt 查找的文件夹中:/lib/binfmt.d/(不是 /var/lib/binfmts/ 由 qemu-user-static 安装)

然后查看状态:

systemctl status systemd-binfmt

然后再次尝试编译您的 docker。它应该有效!

解决方案 2 [当前不适用于 Ubuntu 18.04]

以前是手动配置的过程,现在通过apt包支持:

sudo apt-get install qemu-user-binfmt

有了它,它将在 /proc/sys/fs/binfmt_misc/qemu-* 下为所有平台创建 binfmt 配置。当您的系统检测到可执行文件是针对 arm 的时,它会调用 qemu 而不是尝试直接执行。

这里是更详细解释的链接:https://ownyourbits.com/2018/06/13/transparently-running-binaries-from-any-architecture-in-linux-with-qemu-and-binfmt_misc/https://ownyourbits.com/2018/06/27/running-and-building-arm-docker-containers-in-x86/

要了解它是如何工作的,最好阅读以下段落:

The kernel recognizes the ARM ELF magic, and uses the interpreter /usr/bin/qemu-arm-static , which is the correct QEMU binary for the architecture. 0x7F 'ELF' in hexadecimal is 7f 45 4c 46, so we can see how the magic and the mask work together, considering the structure of the ELF header

typedef struct {
    unsigned char e_ident[EI_NIDENT];   /* 0x7F 'ELF' four byte ELF magic for any architecture */
    uint16_t e_type;
    uint16_t e_machine;                 /* architecture code, 40=0x28 in the case of ARM */
    uint32_t e_version;
    ElfN_Addr e_entry;
    ElfN_Off e_phoff;
    ElfN_Off e_shoff;
    uint32_t e_flags;
    uint16_t e_ehsize;
    uint16_t e_phentsize;
    uint16_t e_phnum;
    uint16_t e_shentsize;
    uint16_t e_shnum;
    uint16_t e_shstrndx;
} ElfN_Ehdr;

请注意 binfmt 配置由 docker 共享,因此它将尝试获取容器内的 /usr/bin/qemu-arm-static。这就是您仍然需要复制/usr/bin/qemu-arm-static 的原因。

关于python - standard_init_linux.go :211:exec user process caused "no such file or directory" with alpine linux and python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58972541/

相关文章:

python - 如何在 python 3 中使用带有并发 future ThreadPoolExecutor 的队列?

python - django queryset运行时-在恒定时间内获取第n个条目

tomcat - 在 docker 容器中处理 tomcat 应用程序的配置

docker - 为什么Docker容器可以看到主机上的所有GPU设备?

amazon-web-services - AWS CodeBuild/codebuild/output/tmp/script.sh : docker: not found

docker - Alpine Dockerfile --no-cache Vs 的优势。 rm/var/cache/apk/*

python - 更改数据帧索引中的数字格式

docker - 当我尝试从 Dockerfile 构建镜像时,为什么会得到 "unzip: short read"?

linux - 如何在 Alpine Linux 上运行 Angular6 E2E 测试

python - 使用Python设置Windows 7时区