Docker healthcheck

I’m trying to set up a simple docker healthcheck for Grafana. Grafana is exposed on host port 3001.

I would expect this to work (as written in docker-compose file)

healthcheck:
  test: curl --fail -s http://localhost:3001/ || exit 1
  interval: 10min
  timeout: 10s 
  retries: 3

But I always get result “unhealthy” as container status.

If I enter the same command curl --fail -s http://localhost:3001/ on my local machine (e.g. in Postman) I see get a Status 200 OK.

Any idea what I’m doing wrong?

Any other ideas how to set up a basic health check for Grafana running in a docker container?

Are you sure that you are using Docker image with curl?

For example latest official image doesn’t have curl, so it can’t be used for healthcheck:

docker run --rm --entrypoint sh -ti grafana/grafana
/usr/share/grafana $ curl
sh: curl: not found

I was of the impression the health checks are run outside the container… If their run inside the container, then yes, this most likely doesn’t work :slight_smile:

Thanks, I will have to do more research.