Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically monitor if a docker container exited?

Tags:

docker

lxc

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.

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

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 ?

like image 646
Nataraj Avatar asked Nov 13 '14 08:11

Nataraj


People also ask

How do I know if my containers are exited?

List Stopped Containers. Stopped containers are those containers that are in exited state. Containers are put into exited state by executing the Docker stop command in them. If you want to list only the stopped containers, you can use the --filter option with a parameter called status.


1 Answers

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

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

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

like image 73
Bryan Avatar answered Sep 20 '22 12:09

Bryan