influxdb icon indicating copy to clipboard operation
influxdb copied to clipboard

Consider adding a HEALTHCHECK instruction to Dockerfile

Open jcoliz opened this issue 1 year ago • 1 comments

Proposal: Add a HEALTHCHECK instruction to Dockerfile

See https://docs.docker.com/engine/reference/builder/#healthcheck

e.g.

HEALTHCHECK --interval=5s --timeout=10s --retries=5 CMD [ "curl", "http://localhost:8086/health" ]

Current behavior: When influxdb is brought up in a container, services which depend on it (like telegraf) won't start properly until influxdb is fully up and accepting connections. So to use docker compose as an example, we need this:

services:
  telegraf:
    image: telegraf:1.26.3-alpine
    depends_on:
      influxdb:
        condition: service_healthy
      mqtt:
        condition: service_healthy
  influxdb:
    image: influxdb:2.7.1-alpine
    healthcheck:
        test: "curl -f http://localhost:8086/health || exit 1"
        interval: 5s
        timeout: 10s
        retries: 5

Desired behavior: Influxdb container can define its own healthcheck, thereby standardizing the health check, and saving users a manual step. Also, it's more likely that you folks as maintainers know the best and most correct health check, as compared to whatever else we come up with as users. Also you'll know the best parameters to the health check, like interval, timeout, etc.

For example, vernemq has this line in the Dockerfile:

HEALTHCHECK &{["CMD-SHELL" "vernemq ping | grep -q pong"] "0s" "0s" "0s" '\x00'}

Alternatives considered: The alternative is to continue to put the work on users to create their own healthcheck instruction.

Use case: This is really more of a completeness and "good behavior" request.

jcoliz avatar Jun 11 '23 16:06 jcoliz

See https://docs.influxdata.com/influxdb/v2/tags/health/, added here. Healthcheck in the compose file:

...
    healthcheck:
      test: influx ping || exit 1
      interval: 60s
      retries: 5
      start_period: 20s
      timeout: 10s

Command:

 $ docker compose exec -it influxdb bash
1269b599ee9a:/# influx ping
OK
1269b599ee9a:/# echo $?
0

sjaakvandenberg avatar Feb 11 '24 17:02 sjaakvandenberg