Loki healthcheck in docker compose

What is the proper healthcheck for Loki in a docker-compose.yml file?
I tried the one below but it does not work.

services
  loki:
    image: grafana/loki:2.9.5
    container_name: loki
    restart: unless-stopped
    command: -config.file=/etc/loki/config.yaml
    ports:
      - 3100:3100 # http
      - 9096:9096 # grpc
    volumes:
      - ./loki/config.yaml:/etc/loki/config.yaml:ro
      - ./.loki:/tmp/loki
    networks:
      - database
    healthcheck:
      test: curl --fail http://localhost:3100/ready || exit 1
      start_period: 20s
      interval: 10s
      timeout: 1s
      retries: 18  # trying for 3 minutes

After running

docker inspect --format "{{json .State.Health }}" loki | jq

i got

{                                           
  "Start": "2024-03-24T22:41:54.084777863Z",
  "End": "2024-03-24T22:41:54.113879119Z",  
  "ExitCode": 1,                            
  "Output": "/bin/sh: curl: not found\n"    
}                                           

which means that curl is not available in the loki container… :unamused:

1 Like

There is no curl, but there is wget. So you may try/use/improve:

    healthcheck:
      test: wget --no-verbose --tries=1 --spider http://localhost:3100/ready || exit 1
1 Like

Thanks for the hint, this seems to work:

healthcheck:
  test: wget --quiet --tries=1 --output-document=- http://localhost:3100/ready | grep -q -w ready || exit 1
  start_period: 20s
  interval: 10s
  timeout: 1s
  retries: 12  # try for 2 minutes