本文介绍了启动容器过程导致& quot; exec:\& quot;/bin/sh \& quot:stat/bin/sh:无此类文件或目录&quot ;:未知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解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 .

日志如下:

当我创建此图像的容器时,它返回:

When I create a container of this image it returns:

docker run my_image

错误是:

有人可以帮助我解决错误吗?

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:无此类文件或目录&quot ;:未知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 02:25