[英]Unable to change the working directory inside a docker container using python script
I am able to get inside a docker container using below command 我可以使用下面的命令进入docker容器
os.system('docker exec -ti $(docker ps -q -a --filter "name=XXXXX") /bin/bash')
and then i need to change to the following directory in the container. 然后我需要更改到容器中的以下目录。
/u01/oracle/weblogic/*****
when i use os.chdir("/u01/oracle/weblogic/*****")
, i am getting No such Directory error
. 当我使用
os.chdir("/u01/oracle/weblogic/*****")
,我收到No such Directory error
。
I could see that os.getcwd()
is still printing the previous directory where the python script is running instead of docker directory. 我可以看到
os.getcwd()
仍在打印运行python脚本的前一个目录而不是docker目录。
Could someone let me know what i am missing ? 有人能让我知道我错过了什么吗?
Why don't you use the container name as exec parameter, instead of using a query to get the id? 为什么不使用容器名称作为exec参数,而不是使用查询来获取id?
You can use the -c parameter of bash to execute multiple commands. 您可以使用bash的-c参数来执行多个命令。 Like:
喜欢:
os.system('docker exec -ti XXXXX /bin/bash -c "cd /tmp;ls -alrt"')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.