<p>If you don't mind running a few other services at your home, then I'd suggest you try Prometheus with Grafana, dockerd-exporter and AlertManager.</p>

<p><a href="https://prometheus.io/docs/introduction/overview/" rel="nofollow noreferrer">Prometheus</a> will store time series data collected from your <a href="https://github.com/stefanprodan/dockerd-exporter" rel="nofollow noreferrer">dockerd-exporter</a>, <a href="http://docs.grafana.org/v4.0/datasources/overview/" rel="nofollow noreferrer">Grafana</a> will display that data in a very nice way and <a href="https://prometheus.io/docs/alerting/alertmanager/" rel="nofollow noreferrer">AlertManager</a> will allow you to configure alerts based on your needs.</p>

<p>Check out a random screenshot I found on Google that presents the solution:
<a href="https://i.sstatic.net/6TSL2.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/6TSL2.png" alt="enter image description here"></a></p>

<p>Also check out <a href="https://github.com/stefanprodan/swarmprom" rel="nofollow noreferrer">swarmprom project</a>.</p>

CC BY-SA 4.0
2019-02-26T09:06:12.227Z
2019-02-26T09:06:12.227Z
Itai Ganot
<p>If most of those are network services, or at least have some administrative TCP/IP port open, then monitoring them by <code>curl</code> or <code>netcat</code> might not be the worst solution. That's how a full-fledged orchestration solution like OpenShift would do it. So, in somewhat increasing order:</p>

<ul>
<li>Check if a TCP/IP port is open (<code>netcat -z</code>)</li>
<li>Check if the port is open and responds with a specific prompt (<code>netcat | grep HELLO</code>).</li>
<li>Check if the port answers with a specific HTML (for example) (<code>curl ... | grep &lt;p&gt;I'm alive&lt;/p&gt;</code>).</li>
</ul>

<p>And finally, if nothing else helps:</p>

<ul>
<li>Check if a hand-written script returns <code>true</code>.</li>
</ul>

CC BY-SA 4.0
2019-02-24T21:52:13.623Z
2019-02-24T21:52:13.623Z
AnoE
<p>You can use check_mk for monitoring the health of containers just as you could for any other machine. Read about it here..</p>

<p><a href="https://mathias-kettner.com/cms_monitoring_docker.html" rel="nofollow noreferrer">Open Source Docker Monitoring Using Check MK</a></p>

<p>Hope this helps.</p>

CC BY-SA 4.0
2019-02-25T07:26:35.180Z
2019-02-25T07:26:35.180Z
KatariaA
<p>Note: answer based only on docs, I didn't play with docker much.</p>

<p>If you choose scripting you could pick a higher layer than just <code>ps</code>, based on either:</p>

<ul>
<li>the <a href="https://docs.docker.com/compose/reference/events/" rel="nofollow noreferrer"><code>docker-compose events</code></a> CLI:</li>
</ul>

<blockquote>
<pre><code>Usage: events [options] [SERVICE...]

Options:
    --json      Output events as a stream of json objects
</code></pre>
  
  <p>Stream container events for every container in the project.</p>
</blockquote>

<ul>
<li>the <a href="https://docs.docker.com/engine/reference/commandline/events/" rel="nofollow noreferrer"><code>docker events</code></a> CLI:</li>
</ul>

<blockquote>
  <p><strong>Description</strong> </p>
  
  <p>Get real time events from the server</p>
</blockquote>

<p>You'd be looking for the <code>die</code> event of the container(from <a href="https://docs.docker.com/engine/reference/commandline/#object-types" rel="nofollow noreferrer">Extended description</a>):</p>

<blockquote>
  <p>Use <code>docker events</code> to get real-time events from the server. These
  events differ per Docker object type.</p>
  
  <p><strong>Object types</strong></p>
  
  <p>CONTAINERS</p>
  
  <ul>
  <li><code>die</code></li>
  </ul>
</blockquote>

<p>The event appears to be generated regardless of the restart policy (from <a href="https://gliderlabs.com/devlog/2015/docker-events-explained/" rel="nofollow noreferrer">Docker Events Explained</a>):</p>

<p><a href="https://i.sstatic.net/6vYMW.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/6vYMW.png" alt="enter image description here"></a></p>

<p>But you're right, there's <a href="https://www.google.com/search?q=docker%20monitor%20container" rel="nofollow noreferrer">a ton of monitoring tools</a> out there, I also suspect some already do what you're seeking.</p>

<p>Just aimlessly wandering through those links I got to <a href="https://scoutapp.com/blog/monitoring-docker-events" rel="nofollow noreferrer">Implementing Docker event monitoring from scratch</a>:</p>

<blockquote>
  <p>What else? <strong>I can create alerts on them</strong>. The next time any of my
  containers decide to puke and die, I can get an SMS message about
  their doomed state.</p>
</blockquote>

CC BY-SA 4.0
2019-02-24T16:49:44.370Z
2019-02-24T16:59:28.927Z
2019-02-24T16:59:28.927Z
Dan Cornilescu
<p>My home server has about 15 distinct services running, each represented by a Docker container. Depending on how the developers implemented the Dockerfile, some services have health checks, but most do not.</p>

<p>At the moment, I do not have a way to make sure these services remain healthy and running. I do have the <code>restart: always</code> setting set, but worst case this just means Docker endlessly restarts a server if it fails to start or crashes on startup for whatever reason. Or maybe a <code>docker pull</code> caused an issue during an update. There could be many reasons why these services do not start, or stop running during the day.</p>

<p>What I'd like is to know when they go down. Maybe an email that notifies me, so I can go fix the issue, instead of only finding out about the issue when a family member notifies me or when I try to use that service.</p>

<p>Is there a reasonable way to monitor multiple Docker containers in this way? Do I have to hand-write a bunch of scripts that do <code>ps</code> to check for process up time or something? Preferably an out-of-the-box solution would be great. Note I use Docker Compose for everything, and I only have 1 physical machine where I run these services, so I don't need to worry about complex setups.</p>

CC BY-SA 4.0
2019-03-04T16:25:05.023Z
Your home server is a highly available kubernetes cluster running on GCP/AWS/Azure/Alibaba cloud...?
simbo1905
CC BY-SA 4.0
2019-03-04T19:19:29.983Z
@simbo1905 Nope, just a little Intel NUC running in my office.
void.pointer
<docker><docker-compose><monitoring>
How do you monitor status of multiple docker containers?
void.pointer
# How do you monitor status of multiple docker containers?

(Asked by: username_0 on 2019-02-24)

My home server has about 15 distinct services running, each represented by a Docker container. Depending on how the developers implemented the Dockerfile, some services have health checks, but most do not.

At the moment, I do not have a way to make sure these services remain healthy and running. I do have the `restart: always` setting set, but worst case this just means Docker endlessly restarts a server if it fails to start or crashes on startup for whatever reason. Or maybe a `docker pull` caused an issue during an update. There could be many reasons why these services do not start, or stop running during the day.

What I'd like is to know when they go down. Maybe an email that notifies me, so I can go fix the issue, instead of only finding out about the issue when a family member notifies me or when I try to use that service.

Is there a reasonable way to monitor multiple Docker containers in this way? Do I have to hand-write a bunch of scripts that do `ps` to check for process up time or something? Preferably an out-of-the-box solution would be great. Note I use Docker Compose for everything, and I only have 1 physical machine where I run these services, so I don't need to worry about complex setups.

**Tags:** docker, docker-compose, monitoring

> **Comments:**
> **username_1**: Your home server is a highly available kubernetes cluster running on GCP/AWS/Azure/Alibaba cloud...?  
> **username_0**: @username_1 Nope, just a little Intel NUC running in my office.  

---

## 4 answers

### Answer by username_5 on 2019-02-24. Score: 3 | Accepted answer

Note: answer based only on docs, I didn't play with docker much.
If you choose scripting you could pick a higher layer than just ps, based on either:

the docker-compose events CLI:


Usage: events [options] [SERVICE...]

Options:
    --json      Output events as a stream of json objects

Stream container events for every container in the project.


the docker events CLI:


Description 
Get real time events from the server

You'd be looking for the die event of the container(from Extended description):

Use docker events to get real-time events from the server. These
  events differ per Docker object type.
Object types
CONTAINERS

die


The event appears to be generated regardless of the restart policy (from Docker Events Explained):

But you're right, there's a ton of monitoring tools out there, I also suspect some already do what you're seeking.
Just aimlessly wandering through those links I got to Implementing Docker event monitoring from scratch:

What else? I can create alerts on them. The next time any of my
  containers decide to puke and die, I can get an SMS message about
  their doomed state.


---

### Answer by username_2 on 2019-02-26. Score: 3

If you don't mind running a few other services at your home, then I'd suggest you try Prometheus with Grafana, dockerd-exporter and AlertManager.

[Prometheus](https://prometheus.io/docs/introduction/overview/) will store time series data collected from your [dockerd-exporter](https://github.com/stefanprodan/dockerd-exporter), [Grafana](http://docs.grafana.org/v4.0/datasources/overview/) will display that data in a very nice way and [AlertManager](https://prometheus.io/docs/alerting/alertmanager/) will allow you to configure alerts based on your needs.

Check out a random screenshot I found on Google that presents the solution:
[![enter image description here](https://i.sstatic.net/6TSL2.png)](https://i.sstatic.net/6TSL2.png)

Also check out [swarmprom project](https://github.com/stefanprodan/swarmprom).


---

### Answer by username_3 on 2019-02-24. Score: 1

If most of those are network services, or at least have some administrative TCP/IP port open, then monitoring them by `curl` or `netcat` might not be the worst solution. That's how a full-fledged orchestration solution like OpenShift would do it. So, in somewhat increasing order:

* Check if a TCP/IP port is open (`netcat -z`)
* Check if the port is open and responds with a specific prompt (`netcat | grep HELLO`).
* Check if the port answers with a specific HTML (for example) (`curl ... | grep

  I'm alive`).

And finally, if nothing else helps:

* Check if a hand-written script returns `true`.


---

### Answer by username_4 on 2019-02-25. Score: 0

You can use check\_mk for monitoring the health of containers just as you could for any other machine. Read about it here..

[Open Source Docker Monitoring Using Check MK](https://mathias-kettner.com/cms_monitoring_docker.html)

Hope this helps.


---

