Alpine Image standard_init_linux.go:207: exec 用户进程导致 "no such file or directory"

Alpine Image standard_init_linux.go:207: exec user process caused "no such file or directory"

我正在尝试 运行 一个基于 alpine 的容器,它将在启动时 运行 一个 hello world C++ 程序。但是,我得到一个 standard_init_linux.go:207: exec user process caused "no such file or directory" 运行 连接容器时出错。

我对容器执行了 ls -al 操作,以检查文件是否具有正确的权限。可执行文件(名为 test)存在于具有 -rwxrwxr-x 权限的根目录中。

这是我的 Dockerfile。

FROM alpine:latest
ADD test /
ENTRYPOINT ["/test"]

有人可以帮助我确定问题所在吗?谢谢!

编辑:我在 Ubuntu 18.04 上编译了我的 .cpp 文件以生成可执行文件。 g++ -o test test.cpp

test.cpp :

#include <iostream>

using namespace std;

int main()
{
   cout<<"Hello World"<<endl;
   return 0;
}

很可能是因为您在非 alpine 操作系统上构建了 test 二进制文件,然后尝试在 alpine 中 运行 它。

例如如果您检查二进制文件的依赖性,您可能会发现下一个(这可能因您的系统而异):

$ ldd test
linux-vdso.so.1
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
/lib64/ld-linux-x86-64.so.2

但是在alpine中,它不使用glibc,它使用musl libc

所以建议大家直接在alpine中搭建出来,或者简单的应用,使用next:

g++ -o test -static test.cpp