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

标签 python docker dockerpy

我正在使用 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/

相关文章:

python - docker -py : How to bind an IP address to a container

python-2.7 - Docker构建失败

python - tensorflow:Label inception 在类别训练中没有图像?

python string.format 和 invalid\x 转义

python - 如何使用 PySide2 在 QWizardPage 中加载 Qt Designer 文件 (.ui)

postgresql - 我们如何将我们的 docker 应用程序连接到本地运行的 postgres?

python - 使用 docker-py 执行 shell 命令

python - 捕获在 docker 容器内运行的 python 脚本的输出

python - Flask-admin 在文本字段旁边创建一个按钮

python - 用 Pandas 进行数据分析?