Running any process from the console can cause an exec error. The first step to fixing this is to see if there is a problem with inputting the data, command or configurations.
Error: /bin/bash no such file or directory
The error message “Starting container process caused exec: … stat /bin/bash: no such file or directory” typically occurs when trying to run a container with an entry point or command that references the /bin/bash shell, but the shell binary is not available or is located in a different path within the container’s filesystem.
What is causing this specific docker error?
Let us simulate this error message by running an Alpine docker container:
[root@codetryout ~]# docker run -it alpine /bin/bash Unable to find image 'alpine:latest' locally Trying to pull repository docker.io/library/alpine ... latest: Pulling from docker.io/library/alpine 89d9c30c1d48: Pull complete Digest: sha256:c19173c5ada610a5989151111163d28a67368362762534d8a8121ce95cf2bd5a Status: Downloaded newer image for docker.io/alpine:latest /usr/bin/docker-current: Error response from daemon: oci runtime error: container_linux.go:235: starting container process caused "exec: "/bin/bash": stat /bin/bash: no such file or directory".
Reason for this error
Look at the last line. It says:
"exec: \"/bin/bash\": stat /bin/bash: no such file or directory".
The alpine image does not come with a bash shell. It has the sh shell.
Solution #1 install the package bash
Here is the detailed guide for installing bash.: How to install bash in docker alpine container
or simply, you can connect to the container and then run the apk add command:
apk add --no-cache bash
Solution #2 use the sh shell instead of Bash
Let us try opening the alpine container again by calling /bin/sh.
docker run -it alpine /bin/sh
And it works!
[root@codetryout ~]# docker run -it alpine /bin/sh / #
It’s worth noting that not all container images include a full shell, such as bash, by default. Some lightweight images or specialized containers may use minimal shells or different entry points. Refer to the documentation or the Dockerfile of the specific image to understand the intended usage and recommended entry points.
I’ve seen many people asking about how to fix this error when trying to run the basic commands in a new docker container like this. Hope this guide helps you to check in the right direction.