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

ExecDockerCd

Exec Problem Overview


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

Exec Solutions


Solution 1 - Exec

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

Solution 2 - Exec

You can't do that, you can do either docker exec -it my_container /bin/bash and then issue several commands with this interactive sessions, or docker exec -d my_container touch myfile if you just want to create a file, see the examples at https://docs.docker.com/reference/commandline/cli/#examples_3

Solution 3 - Exec

If u execute docker container exec --help , it will show the options and method to execute the command Usage: docker container exec [OPTIONS] CONTAINER COMMAND [ARG...]

U have to use docker container exec -it [container_name] bash

Once u are in bash then u can execute any command you wish. Doing CD wont work.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsabarishView Question on Stackoverflow
Solution 1 - ExecAbdullah JibalyView Answer on Stackoverflow
Solution 2 - Execuser2915097View Answer on Stackoverflow
Solution 3 - ExecwhysoserioussonView Answer on Stackoverflow