Running any process from the console can cause an exec error. The first step to fixing this is to determine whether 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. Still, the shell binary is unavailable or 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, 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 the 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 an entire 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 how to fix this error when running the basic commands in a new docker container like this. I hope this guide helps you to check in the right direction.