docker-exec failed: "cd": executable file not found in $PATH

sabarish picture sabarish · Jan 20, 2015 · Viewed 52.7k times · Source

I used this command:
docker exec compassionate_mclean cd /root/python
The error returned is

docker-exec: failed to exec: exec: "cd": executable file not found in $PATH

Kindly help me out

Answer

Abdullah Jibaly picture Abdullah Jibaly · Jan 20, 2015

cd is a built-in shell command, you can't set it as the command to run. You have to use:

docker exec -i compassionate_mclean bash -c "cd /root/python && python myscript.py"

If you want to see the output make sure to add the -i flag as shown above. In this case however, you can simply run python as your entrypoint:

docker exec -i compassionate_mclean python /root/python/myscript.py