简体   繁体   English

docker-exec 失败:“cd”:$PATH 中找不到可执行文件

[英]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 docker-exec:执行失败:exec:“cd”:$PATH 中找不到可执行文件

Kindly help me out请帮帮我

cd is a built-in shell command, you can't set it as the command to run. cd是内置的shell命令,您不能将其设置为要运行的命令。 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. 如果要查看输出,请确保添加-i标志,如上所示。 In this case however, you can simply run python as your entrypoint: 但是,在这种情况下,您可以简单地运行python作为入口点:

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.您可以使用“ docker exec ”命令的-w选项将工作文件夹设置为容器中的绝对路径。 But you would have to set it on every docker-call!但是你必须在每个 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...] 如果您执行docker container exec --help,它将显示执行命令的选项和方法用法:docker container exec [OPTIONS] CONTAINER COMMAND [ARG ...]

U have to use docker container exec -it [container_name] bash 您必须使用docker容器exec -it [container_name] bash

Once u are in bash then u can execute any command you wish. 一旦您处于bash状态,您就可以执行您想要的任何命令。 Doing CD wont work. 做CD是行不通的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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