启动容器进程导致“exec:"/bin/sh": stat/bin/sh: no such file or directory": 未知 [英] 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 "Hellosecond" ---> 使用缓存 ---> 1bbe520f9526 构建成功1bbe520f9526 成功标记 my_image:latest 安全警告:你正在针对非 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": stat/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 scratch
开始的 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.
ENTRYPOINT echo ...
命令被 Docker 重写为 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 scratch
图像并且完全不包含任何内容,因此它不包含 shell,因此会出现/bin/sh: no such file or directory"错误.
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.
这篇关于启动容器进程导致“exec:"/bin/sh": stat/bin/sh: no such file or directory": 未知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!