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 ?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With