# Watch docker container up or down

**URL:** <https://discuss.elastic.co/t/watch-docker-container-up-or-down/206092>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [October 31, 2019, 6:45pm UTC](https://discuss.elastic.co/t/watch-docker-container-up-or-down/206092 "2019-10-31T18:45:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benoit\_Martin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benoit_martin/32/21235_2.png) [@Benoit\_Martin](https://discuss.elastic.co/u/Benoit_Martin)\
**Post date:** [October 31, 2019, 6:45pm UTC](https://discuss.elastic.co/t/watch-docker-container-up-or-down/206092/1 "2019-10-31T18:45:48Z")

</div>

I try to create a watch to alert if one or much from a list of specific container is down. I already use metricbeat to gather the docker container metric. I need help to define this watch. It is not so simple 🙂

Thx in advance!

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [November 4, 2019, 9:54am UTC](https://discuss.elastic.co/t/watch-docker-container-up-or-down/206092/2 "2019-11-04T09:54:02Z")

</div>

Maybe you can share the watch you came up with so far and the output of the execute watch API so we can start debugging step by step?

--Alex

---

<div class="post-metadata">

**Author:** ![Benoit\_Martin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benoit_martin/32/21235_2.png) [@Benoit\_Martin](https://discuss.elastic.co/u/Benoit_Martin)\
**Post date:** [November 5, 2019, 2:28pm UTC](https://discuss.elastic.co/t/watch-docker-container-up-or-down/206092/3 "2019-11-05T14:28:31Z")

</div>

This is what I do for the moment.

```json
{
  "trigger": {
    "schedule": {
      "interval": "5m"
    }
  },
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": [
          "metricbeat-*"
        ],
        "rest_total_hits_as_int": true,
        "body": {
          "size": 0,
          "query": {
            "bool": {
              "must": [
                {
                  "match_phrase": {
                    "container.name": {
                      "query": "myspecifycontainer"
                    }
                  }
                },
                {
                  "range": {
                    "@timestamp": {
                      "format": "strict_date_optional_time",
                      "gte": "now-5m/m",
                      "lt": "now/m"
                    }
                  }
                }
              ],
              "filter": [
                {
                  "bool": {
                    "should": [
                      {
                        "match_phrase": {
                          "docker.healthcheck.status": "healthy"
                        }
                      }
                    ],
                    "minimum_should_match": 1
                  }
                }
              ],
              "should": [],
              "must_not": []
            }
          }
        }
      }
    }
  },
  "condition": {
    "compare": {
      "ctx.payload.hits.total": {
        "gte": 10
      }
    }
  },
  "actions": {
    "my-logging-action": {
      "logging": {
        "level": "info",
        "text": "My Query is not healthy."
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [November 5, 2019, 8:30pm UTC](https://discuss.elastic.co/t/watch-docker-container-up-or-down/206092/4 "2019-11-05T20:30:15Z")

</div>

do you care to explain what is not working? Also the output of the execute watch api is missing. Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 3, 2019, 8:30pm UTC](https://discuss.elastic.co/t/watch-docker-container-up-or-down/206092/5 "2019-12-03T20:30:18Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
