希望你能帮忙。我需要在我的 Python 脚本中运行带有特定图像(在我的例子中是 Fenics)的软件容器 Docker,然后向他传递一个命令来执行脚本。
我试过子流程:
cmd1 = 'docker exec -ti -u fenics name_of_my_container /bin/bash -l'
cmd2 = 'python2 shared/script_to_be_executed.py'
process = subprocess.Popen(shlex.split(cmd1),
stdout=subprocess.PIPE,stdin=subprocess.PIPE, stderr =
subprocess.PIPE)
process.stdin.write(cmd2)
print(first_process.stdout.read())
但它什么也没做。建议?