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
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.
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.