如何以编程方式监视docker容器是否退出? [英] How to programmatically monitor if a docker container exited?

查看:127
本文介绍了如何以编程方式监视docker容器是否退出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的VM Host上运行多个命名的Docker容器(200+)。
我有一个管理器脚本/代码,应该从主机管理容器。
我想知道是否有任何基于事件的机制来在容器停止/失败时得到通知。这样我可以重新启动已停止的容器。

I am running multiple named docker containers (200+) on my VM Host. I have a manager script/code that is supposed to manage the containers from the host. I would like to know if there is any event-based mechanism to get notified when a container stops/fails. So that I can restart the stopped container.

我能想到的一个解决方案是定期对docker检查并查看 State.Pid State。运行以确认状态。

One solution I could think of is doing a periodic docker inspect and looking at State.Pid or State.Running to confirm the status.

但是,它不是定期轮询,而是如果在容器发生故障时以pid / name通知管理器,以便经理可以单独重新启动特定容器,那将更好。

But,instead of periodic polling, it would be better if the manager is notified with pid/name when a container fails so that, the particular container alone can be restarted.

总的来说,有什么办法以编程方式监视不是父进程的其他进程的进程状态?

On a general note, are there ways to programmatically monitor the status of a process from a different process that is not the parent ?

推荐答案

查看 docker事件-容器'die'有一个事件。

Look at docker events - there is an event for container 'die'.

还有一个http界面可以获取相同的信息以编程方式-请参见此处

There is also an http interface to get the same information programmatically - see here

您可能想在网络上搜索 docker Orchestration-许多项目如雨后春笋般地以您描述的方式管理多个容器。

You may want to do a web search for 'docker orchestration' - many projects springing up to manage multiple containers in the way you describe.

这篇关于如何以编程方式监视docker容器是否退出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆