Container will not start: stat /bin/sh: no such file or directory
starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknownShort answer
Docker tried to run your command through /bin/sh and the image has no shell. That happens with scratch and distroless images when CMD, ENTRYPOINT or RUN is written as a plain string. Write the command as a JSON array so no shell is needed, and run build steps in an earlier stage.
Fix it fast
1Find out which cause you have
Print how the image starts. A command stored as ["/bin/sh","-c","..."] means the Dockerfile used the string form.
docker image inspect --format 'entrypoint={{json .Config.Entrypoint}} cmd={{json .Config.Cmd}}' my-image2Match what you see, then jump to its fix
- 1
The inspect output starts with /bin/sh and -cCMD or ENTRYPOINT is written in shell form on an image without a shellFix - 2
The build, not the run, fails on a RUN line after FROM scratch or a distroless FROMA RUN instruction sits in a final stage that is scratch or distrolessFix - 3
docker run -it my-image sh or docker exec -it ... sh gives the same errorYou ran sh yourself to look inside, and the image has noneFix
- 1
What does the error look like?
starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknownexec: "/bin/sh": stat /bin/sh: no such file or directory
Cause 1 of 3
CMD or ENTRYPOINT is written in shell form on an image without a shell
1Check
Look at the last CMD and ENTRYPOINT lines in the Dockerfile. A plain string such as CMD node server.js is wrapped as /bin/sh -c by Docker. Distroless images contain no shell at all.
grep -n -E '^(CMD|ENTRYPOINT)' Dockerfile2Fix
Use the exec form, a JSON array with double quotes, with the full path of the program.
# wrong on an image without a shell
CMD /app/server
# right
CMD ["/app/server"]3Verify
Rebuild and start the container.
docker build -t my-image .
docker run --rm my-imageConfirmed by docs.docker.com
Cause 2 of 3
A RUN instruction sits in a final stage that is scratch or distroless
1Check
RUN in shell form always goes through a command shell, so it cannot work in a stage whose base has none.
grep -n -E '^(FROM|RUN)' Dockerfile2Fix
Do the installing, compiling and file preparation in an earlier stage that has a shell, then copy only the result into the final stage.
FROM golang:1.24 AS build
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 go build -o /out/server .
FROM scratch
COPY --from=build /out/server /server
CMD ["/server"]3Verify
Build the image again.
docker build -t my-image .Confirmed by docs.docker.com
Cause 3 of 3
You ran sh yourself to look inside, and the image has none
1Check
Distroless images ship without shells and package managers on purpose, so docker exec and docker run with sh cannot work.
docker run --rm -it --entrypoint sh my-image2Fix
Attach a debug shell without changing the image with docker debug, or build from the distroless debug variant, which includes a busybox shell.
docker debug my-container
# or in the Dockerfile, for the debug build only
FROM gcr.io/distroless/python3-debian13:debug
# then
docker run --entrypoint=sh -ti my_debug_image3Verify
A prompt opens inside the container or image.
ls /Confirmed by docs.docker.com
How do I stop it coming back?
- Write CMD and ENTRYPOINT in exec form in every Dockerfile, with absolute paths.
- Keep build steps in a builder stage and make the final stage copy-only.
- Keep a :debug variant or docker debug at hand before you need it in an incident.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
A Docker container exits with 'no such file or directory' though the file exists
standard_init_linux.go:190: exec user process caused "no such file or directory"
The kernel returns this error when the file's interpreter is missing, not only the file.
3 causes, each with a fixServers
docker run fails because the executable is not found in the container
OCI runtime create failed: ... executable file not found in $PATH: unknown
Docker looked for the program you named inside the container image and did not find it.
3 causes, each with a fixServers
apk cannot find py-pip in an Alpine Docker image
py-pip (no such package):
On current Alpine releases there is no package called py-pip.
2 causes, each with a fixServers
ng serve runs in the container but localhost:4200 does not open
The browser cannot open localhost:4200 although ng serve is running in the container
ng serve listens on localhost by default, which inside a container is the container itself.
3 causes, each with a fixServers
Angular routes return 404 from nginx when you refresh or open a link
The home page loads, but refreshing /some/route shows an nginx 404
Angular routes like /users/42 are not files, so nginx looks for them on disk and returns 404.
3 causes, each with a fixServers
AH00558: Apache in Docker cannot reliably determine its fully qualified domain name
Set the 'ServerName' directive globally to suppress this message
AH00558 is a warning, not a crash.
2 causes, each with a fix