How to fix docker error executable file not found in $PATH?
You might have encountered the error executable file not found in $PATH when you are trying to run your docker container. There could be many reasons for an error like this. But in simple words, the docker can not find the binary which you want to run inside the docker container.
Let's take some examples to identify the root cause behind the error executable file not found in $PATH and we will also see how to troubleshoot it. Since it is a very generic error thrown by the docker container, so most importantly we should understand the error.
Example 1 - python
Here is a first error example in which it is complaining about the python -
1exec: "python": executable file not found in $PATH
Generally, we tend to focus on the remaining part of the error but if you look carefully in the above error then it stats the exec: "python" which mean the docker entrypoint_ is not able to run or execute the python program_.
How to fix it?
There could be reasons behind this issue -
- Python is not installed - The python is not installed or you are missing python install instructions in your dockerfile. Here are the instructions for adding python alongside your dockerfile -
1FROM ubuntu 2RUN apt-get update 3RUN apt-get install -y python3.8 4ENTRYPOINT ["python3"]
- You are still using old python - The second reason could be that you are using the old Python<3 and any version of python lesser then 3 has been deprecated and not supported.
Example 2 - grunt serve
The one more example which I can recall about running grunt serve using docker CMD
Here is the code snippet of the docker file where I am trying to execute the grunt serve -
1EXPOSE 9000 57789 2CMD ["grunt"]
But when I try to run the docker container it throws the following error -
1exec: "grunt serve": executable file not found in $PATH
Again here in the above error message, you will notice exec: "grunt serve" which means there is the problem while executing the grunt command inside your docker container.
How to fix it?
Here are the possible ways to fix the issue -
- Do not use CMD ["grunt"] instead use CMD grunt - One of the most probable reasons for this issue is you are using CMD ["grunt"] instead of CMD grunt. What happens when you use CMD ["grunt"] it becomes a JSON array whenever you surround it with double-quotes. It will also be executed without a shell and if you do not have a shell then all of your environment variables will not be available.
Once you specify the same command without any double-quotes .e.g CMD grunt then the command grunt will be executed with /bin/sh -c
Example 3 - Executing custom shell script
The third use case could be the custom shell script(my-custom-script.sh) which you want to execute during the docker run process.
Here is a little code snippet of the dockerfile in which I am trying to execute my-custom-script.sh.
1COPY my-custom-script.sh /usr/local/bin 2ENTRYPOINT ["my-custom-script.sh"]
But when I try to run the docker container it throws me an error -
1 exec: "my-custom-script.sh": executable file not found in $PATH
If you look at the above error then you can see docker can not execute the shell script(my-custom-script.sh)
How to fix it?
- Make sure the script my-custom-script.sh is available - the First check which you should perform is by checking the shell script my-custom-script.sh if it's available or not. Mostly we try to copy the custom shell script inside the dockerfile ex. - COPY my-custom-script.sh /usr/local/bin but we do not pay attention on destination. If you want the script to be available in $PATH then make sure it is copied to the directory /usr/local/bin.
- Check the executable permission - The second check which I would recommend for the permission. Make sure the custom script has_executable permission(+x)_
Posts in this Series
- How to push Docker Images to AWS ECR(Elastic Container registry)?
- How to Copy Docker images from one host to another host?
- What is persistent storage in docker and how to manage it
- Docker Installation on MacOS, Linux and Windows
- Docker - ADD, Update, Export Environment variable
- How to fix-Docker docker failed to compute cache key not found
- How to fix docker driver failed programming external connectivity on endpoint webserver?
- How to fix docker error executable file not found in $PATH?
- How to expose port on live containers?
- How to expose multiple ports with Docker?
- How to restart single docker container within multiple docker container?
- How to edit file within Docker container or edit a file after I shell into a Docker container?
- How to fix Error starting docker service Unit not found?
- How to remove old, unused images of Docker?
- How to fix docker error invalid reference format error?
- How to fix requested access to the resource is denied?
- How to fix Docker error cannot delete docker container conflict unable to remove repository reference?
- How to fix docker error no space left on device?
- How to connect localhost from docker container?
- Docker COPY vs Docker ADD?
- 6 Ways to fix - Got permission denied while trying to connect to the Docker daemon socket?
- 6 Ways to fix – Docker COPY failed: stat no source files were specified