【发布时间】:2019-02-12 20:50:34
【问题描述】:
我打算将 docker 用于 c++ 项目。 我添加了一个简单的 C++ 程序,它打印“hello world”来测试它。 然后我编译了它
g++ -o helloworldexecutable helloword.cpp
将 Dockerfile 添加到项目根文件夹 Dockerfile 包括:
FROM scratch
ADD helloworldexecutable /
CMD helloworldexecutable
当我运行时:sudo docker build --tag helloworldexecutable . 它表明构建成功。我看到这张图片使用sudo docker images
我可以启动 sudo docker run hello-world 但运行 sudo docker run helloexecutable 我得到一个错误:
docker:来自守护进程的错误响应:OCI 运行时创建失败:container_linux.go:344:启动容器进程导致“exec:\”/bin/sh\“:stat /bin/sh:没有这样的文件或目录”:未知。
可能是什么问题?
【问题讨论】:
-
helloworldexecutable可能没有执行权限。你也不需要像./helloworldexecutable那样在可执行文件前面加上./吗? -
它确实有执行权限。不,你没有
-
它是动态链接的,但
FROM scratch图像不包含任何库,甚至不包含运行它所需的动态加载器。 -
另外,如果你说
CMD helloworldexecutable,Docker 会尝试运行/bin/sh -c 'helloworldexecutable',而FROM scratch映像没有/bin/sh。 -
@DavidMaze 虽然它没有修复根本问题,但您仍应添加您的评论作为答案,因为它直接回答了“为什么会发生此错误? "
标签: c++ docker dockerfile