启动容器过程导致& quot; exec:\& quot;/bin/sh \& quot:stat/bin/sh:无此类文件或目录" ;:未知 [英] Starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknown
问题描述
我想了解CMD和ENTRYPOINT的工作原理.因此,我刚刚创建了一个非常简单的 Dockerfile
I want to understand how CMD and ENTRYPOINT works. So, I just created a very simple Dockerfile
FROM scratch
CMD echo "Hello First"
ENTRYPOINT echo "Hello second"
然后我构建此图像:
docker build -t my_image .
日志如下:
第1/3步:从头开始--->第2/3步:CMD回显"Hello First" --->使用缓存---> 9f2b6a00982f步骤3/3:ENTRYPOINT echo"Hello秒"--->使用缓存---> 1bbe520f9526成功构建1bbe520f9526已成功标记my_image:最新安全警告:您正在针对非Windows Docker从Windows构建Docker映像主持人.所有添加到构建上下文的文件和目录都将具有'-rwxr-xr-x'权限.建议仔细检查并重设敏感文件和目录的权限.
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.
当我创建此图像的容器时,它返回:
When I create a container of this image it returns:
docker run my_image
错误是:
docker:来自守护程序的错误响应:OCI运行时创建失败:container_linux.go:344:启动容器进程引起的"exec:\"/bin/sh \":统计信息/b in/sh:没有这样的文件或目录:未知.
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.
有人可以帮助我解决错误吗?
Can someone please help me about error?
推荐答案
这里发生了两件事.
以 FROM从头开始
的Dockerfile从根本没有任何内容的基础映像开始.它是完全空的.除了Docker为您提供的几个设备文件之外,没有一组基础工具或库或其他任何东西.
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.
Docker将 ENTRYPOINT echo ...
命令重写为 ENTRYPOINT ["/bin/sh",-c","echo ..."]
,并导致完全忽略 CMD
.除非被 docker run --entrypoint
覆盖,否则它将成为容器运行的主要过程.
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.
由于它是 FROM临时
映像,并且完全不包含任何内容,因此它不包含外壳程序,因此出现"/bin/sh:无此类文件或目录"错误.
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.
这篇关于启动容器过程导致& quot; exec:\& quot;/bin/sh \& quot:stat/bin/sh:无此类文件或目录" ;:未知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!