当我使用python subprocess.run('docker build ...')时'没有这样的文件或目录'

时间:2018-11-13 16:11:24

标签: python docker

在ubuntu18.04中

我正在编写python脚本来构建docker映像,然后执行其他操作,main.py在这里:

from subprocess import run
run('docker build --rm -f "Dockerfile" -t test:latest .')
...

然后发生错误:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/subprocess.py", line 403, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'docker build --rm -f "Dockerfile" -t test:latest .': 'docker build --rm -f "Dockerfile" -t test:latest .'

Dockerfilemain.py放在一起时,可以直接在shell中运行build命令。

0 个答案:

没有答案