我正在看
standard_init_linux.go:207: exec user process caused "exec format error"
将我的 helloWorldC 镜像作为容器运行时出错。可能是什么问题呢?任何帮助表示赞赏。
我在带有 Docker 桌面社区版的 MacOS 上尝试了以下步骤。
编写了一个简单的 C++ 程序,编译并创建了一个可执行文件。
$ cat helloWorldC.cc
#include<iostream>
using namespace std;
int main() {
cout << "###############################################################\n";
cout << "\tHello from basic C++ HelloWorld Dockerized image \n ";
cout << "###############################################################\n";
return 0;
}
$
$ clang++ -o helloWorldC helloWorldC.cc
$ ./helloWorldC
###############################################################
Hello from basic C++ HelloWorld Dockerized image
###############################################################
$
然后为我的“helloWorldC”可执行文件创建了一个简约的 Dockerfile -
$ cat Dockerfile
FROM scratch
ADD helloWorldC /
CMD ["/helloWorldC"]
$
构建了一个 docker 镜像 -
$ docker build --tag helloworldc .
Sending build context to Docker daemon 550.9kB
Step 1/3 : FROM scratch
--->
Step 2/3 : ADD helloWorldC /
---> 35c21b2c67c9
Step 3/3 : CMD ["/helloWorldC"]
---> Running in bc22fbf4bf85
Removing intermediate container bc22fbf4bf85
---> 96e44669461a
Successfully built 96e44669461a
Successfully tagged helloworldc:latest
$
Docker 镜像创建成功——
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
.
.
helloworldc latest 96e44669461a About a minute ago 15.4kB
registry 2 f32a97de94e1 44 hours ago 25.8MB
.
.
$
在运行 Docker 容器时,我看到以下错误。
$ docker run helloworldc
standard_init_linux.go:207: exec user process caused "exec format error"
$
以下是我的 docker 版本 -
$ docker version
Client: Docker Engine - Community
Version: 18.09.1
API version: 1.39
Go version: go1.10.6
Git commit: 4c52b90
Built: Wed Jan 9 19:33:12 2019
OS/Arch: darwin/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.1
API version: 1.39 (minimum version 1.12)
Go version: go1.10.6
Git commit: 4c52b90
Built: Wed Jan 9 19:41:49 2019
OS/Arch: linux/amd64
Experimental: false
$
最佳答案
我想建议一个替代解决方案,它使您能够编译代码并根据需要保持最终图像最小化。这可以使用 multi-stage builds 来完成。由 docker 提供。所以你的 Dockerfile 可以是这样的:
FROM gcc:5 as builder
COPY ./helloWorldC.cc /helloWorldC.cc
RUN g++ -o helloWorldC -static helloWorldC.cc && chmod +x helloWorldC
FROM scratch
COPY --from=builder /helloWorldC /helloWorldC
CMD ["/helloWorldC"]
然后在构建之后,您将拥有一个像这样的最小图像:
REPOSITORY TAG IMAGE ID CREATED SIZE
helloworldimage latest 89800885c997 22 seconds ago 2.17MB
最后,您可以毫无问题地运行它:
docker run --rm -it helloworldimage:latest
###############################################################
Hello from basic C++ HelloWorld Dockerized image
###############################################################
关于macos - 运行私有(private) docker 镜像 : standard_init_linux. go:207 时出错:执行用户进程导致 "exec format error",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55082993/