简体   繁体   English

检查容器退出状态的快速方法

[英]Fast way to check container exit status

I need a fast way to check if a containers has exited in a scriptable way.我需要一种快速的方法来检查容器是否以可编写脚本的方式退出。 Currently using docker library with python but that creates too much overhead.目前在 python 中使用 docker 库,但这会产生太多的开销。

docker inspect -f {{.State.Status}} $CONTAINER_PID Any suggestions? docker inspect -f {{.State.Status}} $CONTAINER_PID什么建议吗?

Try doing it by using the subprocess package (the shell=True is important):尝试使用 subprocess 包( shell=True很重要)来做到这一点:

import subprocess

output = subprocess.check_output(r"docker inspect -f {{.State.Status}} $CONTAINER_PID", shell=True).decode()

print(output)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM