问题描述
我有一个目录,其中包含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安装行抛出:
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]
来自我们可以看到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
这将删除 qemu-解决方案2中的user-binfmt
方法。但是,在该软件包中,提供的配置文件不在文件夹中,并且配置错误,供 systemd-binfmt $ c $使用c>。
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 /
(不是由qemu-user-static安装的 / var / lib / binfmts /
)
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
以此创建 binfmt 在
/ proc / sys / fs / binfmt_misc / qemu-*
下所有平台的code>配置。当您的系统检测到可执行文件是供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.
此处是指向更详细说明的链接:或
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:
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用户进程导致“无此文件或目录”。与高山linux和python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!