Starting container process caused “exec: \”/bin/sh\“: stat /bin/sh: no such file or directory”: unknown

后端 未结 2 923
情歌与酒
情歌与酒 2021-02-12 10:51

I want to understand how CMD and ENTRYPOINT works. So, I just created a very simple Dockerfile

FROM scratch

CMD echo \"Hello First\"

ENTRYPOINT ec         


        
2条回答
  •  旧巷少年郎
    2021-02-12 11:14

    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.

    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.

    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.

提交回复
热议问题