Skip to main content
 首页 » 编程设计

python之我如何检测 docker-py client.build() 何时失败

2024年08月23日32jirigala

我正在使用 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']))