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

后端 未结 2 914
情歌与酒
情歌与酒 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.

    0 讨论(0)
  • 2021-02-12 11:35

    I have solved a similar problem deleting all the Docker images with a

    docker rmi -f $(docker images -aq)
    

    and restarting Docker.

    Another option is to reset to factory defaults through the Docker desktop dashboard. Mind that this will remove all of your images, containers, settings so on so forth.

    0 讨论(0)
提交回复
热议问题