简体   繁体   中英

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

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

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

您不能这样做,可以执行docker exec -it my_container /bin/bash ,然后在此交互式会话中发出几个命令,或者docker exec -d my_container touch myfile如果您只想创建文件),请参见示例在https://docs.docker.com/reference/commandline/cli/#examples_3

You can use the -w option of the ' docker exec '-command to set the working-folder as an absolute path in the container. But you would have to set it on every docker-call!

eg

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM