bash 启动容器进程导致 "exec:\"/bin/sh\": stat /bin/sh: no such file or directory": unknown
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/54820846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknown
提问by Mehraj Malik
I want to understand how CMD and ENTRYPOINT works. So, I just created a very simple Dockerfile
我想了解 CMD 和 ENTRYPOINT 的工作原理。所以,我只是创建了一个非常简单的Dockerfile
FROM scratch
CMD echo "Hello First"
ENTRYPOINT echo "Hello second"
Then I build image of this :
然后我建立这个形象:
docker build -t my_image .
The logs are as below:
日志如下:
Step 1/3 : FROM scratch ---> Step 2/3 : CMD echo "Hello First" ---> Using cache ---> 9f2b6a00982f Step 3/3 : ENTRYPOINT echo "Hello second" ---> Using cache ---> 1bbe520f9526 Successfully built 1bbe520f9526 Successfully tagged my_image:latest SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context w ill have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.
步骤 1/3:从头开始 ---> 步骤 2/3:CMD echo "Hello First" ---> Using cache ---> 9f2b6a00982f Step 3/3:ENTRYPOINT echo "Hello second" ---> Using cache ---> 1bbe520f9526 成功构建 1bbe520f9526 成功标记 my_image:latest 安全警告:您正在针对非 Windows Docker 主机从 Windows 构建 Docker 映像。添加到构建上下文的所有文件和目录都将具有“-rwxr-xr-x”权限。建议仔细检查并重置敏感文件和目录的权限。
When I create a container of this image it returns:
当我创建此图像的容器时,它返回:
docker run my_image
Error is:
错误是:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "exec: \"/bin/sh\": stat /b in/sh: no such file or directory": unknown.
docker:来自守护进程的错误响应:OCI 运行时创建失败:container_linux.go:344:启动容器进程导致“exec:\”/bin/sh\“:stat /b in/sh:没有这样的文件或目录”:未知。
Can someone please help me about error?
有人可以帮我解决错误吗?
采纳答案by David Maze
There are two things happening here.
这里发生了两件事。
A Dockerfile that starts FROM scratch
starts from a base image that has absolutely nothing at all in it. It is totally empty. There is not a set of base tools or libraries or anything else, beyond a couple of device files Docker pushes in for you.
一个 DockerfileFROM scratch
从一个完全没有任何内容的基础镜像开始。它完全是空的。除了 Docker 为您推送的几个设备文件之外,没有一组基本工具或库或其他任何东西。
The ENTRYPOINT echo ...
command gets rewritten by Docker into ENTRYPOINT ["/bin/sh", "-c", "echo ..."]
, and causes the CMD
to be totally ignored. Unless overridden with docker run --entrypoint
, this becomes the main process the container runs.
该ENTRYPOINT echo ...
命令被 Docker 重写为ENTRYPOINT ["/bin/sh", "-c", "echo ..."]
,并导致CMD
被完全忽略。除非被覆盖docker run --entrypoint
,否则这将成为容器运行的主要进程。
Since it is a FROM scratch
image and contains absolutely nothing at all, it doesn't contain a shell, hence the "/bin/sh: no such file or directory" error.
由于它是一个FROM scratch
图像并且完全不包含任何内容,因此它不包含外壳,因此会出现“/bin/sh: no such file or directory”错误。