我正在使用 docker-py 来构建和运行 Docker 镜像。
来自阅读the documentation我不清楚我应该如何检测构建图像是否有错误。 build()
不会在出现错误时引发异常。这让我觉得我必须调查返回的响应。
确定 docker-py 的 client.build() 是否失败的最佳方法是什么?
最佳答案
看起来“最好”的方法是解码响应并查找名为“error”的键。
例如:
for response in client.build(path, tag, decode=True):
if response.has_key('error'):
raise Exception("Error building docker image: {}".format(response['error']))
关于python - 我如何检测 docker-py client.build() 何时失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33570014/