standard_init_linux.go:211:exec 用户进程导致“没有这样的文件或目录";使用 alpine linux 和 python [英] standard_init_linux.go:211:exec user process caused "no such file or directory" with alpine linux and python
问题描述
我有一个包含 docker 文件、attack.py 和 requirements.txt 的目录.
I have a directory which contains the docker file, a attack.py and a requirements.txt.
使用它,我创建了以下 dockerfile:
Using that, I created the following 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 install 行抛出:standard_init_linux.go:211:exec 用户进程导致没有这样的文件或目录"
However, the pip install line throws: standard_init_linux.go:211:exec user process caused "no such file or directory"
我不知道为什么.使用 ls、pwd 等命令尝试调试会产生相同的错误.
I can't figure out why. Using commands like ls, pwd and so on in an attempt to debug this yields the same error.
谁能解释一下我到底做错了什么?
Can anyone explain what exactly I am doing wrong?
推荐答案
我猜你想在非 arm64v8 平台上构建 docker 镜像.对于其余的答案,我会假设.
I guess you are trying to build the docker image on a non-arm64v8 platform. I would assume that for the rest of the answer.
提供的解决方案将特定于 Ubuntu 发行版(主机),但我想在其他 linux 发行版上应该是类似的.
The solution provided will be specific for Ubuntu distribution (host), but I guess it should be similar on other linux distribution.
解决方案 1 [使用 Ubuntu 18.04]
SOLUTION 1 [working on Ubuntu 18.04]
来自 https://github.com/docker/for-linux/issues/56 我们可以看到目前 Debian(以及 Ubuntu?)的软件包中存在错误.
From https://github.com/docker/for-linux/issues/56 we can see that there is bug currently in the packages for Debian (and thus 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
.
This will remove the qemu-user-binfmt
method from solution 2. However in that package the provided configuration files are not in the folder, and missconfigured, to be used by systemd-binfmt
.
此外,我们从 git 存储库中获取配置文件并将它们放在 systemd-binfmt 查看的文件夹中:/lib/binfmt.d/
(不是 /var/lib/binfmts/
由 qemu-user-static 安装)
Also, we get the configuration files from a git repository and place them in a folder where the systemd-binfmt looks into: /lib/binfmt.d/
(not /var/lib/binfmts/
as install by qemu-user-static)
然后检查状态:
systemctl status systemd-binfmt
并尝试再次编译您的 docker.它应该可以工作!
And try to compile your docker again. It should work!
解决方案 2 [目前不适用于 Ubuntu 18.04]
SOLUTION 2 [not currently working on Ubuntu 18.04]
以前是手动配置过程,现在通过apt包支持:
It used to be a manually configuration process on previous, but now it is supported via a apt package:
sudo apt-get install qemu-user-binfmt
它会在 /proc/sys/fs/binfmt_misc/qemu-*
下为所有平台创建 binfmt
配置.当你的系统检测到可执行文件是针对 arm 的,它会调用 qemu 而不是尝试直接执行.
With that it will create the binfmt
configuration for all platforms under /proc/sys/fs/binfmt_misc/qemu-*
. And when your system detects that the executable is for arm, it will call qemu instead of trying to execute directly.
这里是更详细解释的链接: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/
Here is a link to a more detailed explanation: https://ownyourbits.com/2018/06/13/transparently-running-binaries-from-any-architecture-in-linux-with-qemu-and-binfmt_misc/ or https://ownyourbits.com/2018/06/27/running-and-building-arm-docker-containers-in-x86/
要了解它是如何工作的,最好阅读以下段落:
To understand how it works, it is good to the following paragraph:
内核识别ARM ELF魔法,并使用解释器/usr/bin/qemu-arm-static
,这是正确的 QEMU 二进制文件建筑学.0x7F 'ELF' 十六进制是7f 45 4c 46
,所以我们可以看看魔法和面具是如何协同工作的,考虑到ELF头的结构
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 is7f 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 的原因.
Note that the binfmt
configuration is shared by docker, therefore it will trying to get the /usr/bin/qemu-arm-static
inside the container. And that is the reason you still need to copy the /usr/bin/qemu-arm-static.
这篇关于standard_init_linux.go:211:exec 用户进程导致“没有这样的文件或目录";使用 alpine linux 和 python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!