需要在python脚本中运行docker run命令 [英] Need to run docker run command inside python script
本文介绍了需要在python脚本中运行docker run命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Docker命令是:
My Docker Command is:
docker run --rm wappalyzer/cli https://wappalyzer.com
当我运行python脚本时:
When I run my python script:
#!/usr/bin/python
from subprocess import call
import json
import os
import docker
docker run --rm wappalyzer/cli "MYURL"
它说
File "t.py", line 7
docker run --rm wappalyzer/cli "MYURL"
^
SyntaxError: invalid syntax
我的操作系统是ubuntu 14.04,我正在使用ubuntu终端.
My os is ubuntu 14.04 and I am using ubuntu terminal.
推荐答案
正如@AndyShinn所说,Python不是Shell语言,但是您可以像运行Shell命令一样调用Docker:
As @AndyShinn says, Python is not a shell language, but you can call to docker as if you were running a shell command:
#!/usr/bin/python
import subprocess
with open("/tmp/output.log", "a") as output:
subprocess.call("docker run --rm wappalyzer/cli https://wappalyzer.com", shell=True, stdout=output, stderr=output)
使用这种方法,您无需导入docker.
With this approach you don't need to import docker.
这篇关于需要在python脚本中运行docker run命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文