[英]How to get logs when build fails in docker-py?
If I build an image using the high-level docker-py sdk, I get a BuildError on failure., eg 如果我使用高级docker-py sdk构建映像,则在失败时会收到BuildError,例如
try:
client.images.build(...)
except:
print("Hey something wrong with image build!")
I know I can use the low level client API to directly hook in and stream logs, see How can I detect when docker-py client.build() fails . 我知道我可以使用低级客户端API直接挂接和流式传输日志,请参阅如何检测docker-py client.build()何时失败 。
Is there a way to get some useful debug output from the image build script without going down to the lower level api? 有没有一种方法可以从映像构建脚本中获得一些有用的调试输出,而无需使用较低级别的api?
As of Docker 3.x, the BuildError contains a new build_log
variable which is a generator of output: 从Docker 3.x开始,BuildError包含一个新的build_log
变量,它是输出的生成器:
try:
return client.images.build(...)
except BuildError as e:
print("Hey something went wrong with image build!")
for line in e.build_log:
if 'stream' in line:
logger.error(line['stream'].strip())
raise
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.