Check if clickhouse is healthy docker-compose
Asked Answered
D

1

8

I need to wait for Clickhouse to start before I can start my backend server, however the healthcheck does not work.

Here is my docker-compose.yml file:

version: '3.9'
services:
  server:
    build: .
    depends_on:
      clickhouse:
        condition: service_healthy

  clickhouse:
    image: yandex/clickhouse-server
    ports:
      - '8123:8123'
      - '9000:9000'
      - '9009:9009'
    healthcheck:
      test: ['CMD', 'curl', '-f', 'http://localhost:8123']
      interval: 5s
      timeout: 3s
      retries: 5

However when I run docker-compose up --build, then you can see the Clickhouse server starting, everything is fine, however the healthcheck never passes. The command exits preemptively with the error: container for service "Clickhouse" is unhealthy. However, if, during this time, I go run the command curl -f http://localhost:8123 on my own computer (outside of the docker container) then it returns Ok.

So is there a way to wait for Clickhouse to be healthy before starting another service?

Dichotomous answered 11/8, 2022 at 19:12 Comment(1)
are you sure curl present inside container?Wilden
P
13

Try this way:

    ..
    healthcheck:
      test: wget --no-verbose --tries=1 --spider http://localhost:8123/?query=SELECT%201 || exit 1
    ..

or

    ..
    healthcheck:
      test: wget --no-verbose --tries=1 --spider http://localhost:8123/ping || exit 1
    ..
Preventer answered 11/8, 2022 at 19:47 Comment(1)
For readers don't use '--spider' together with '/?query' because then clickhouse following error occurs: "DynamicQueryHandler: Cannot flush data to client: Code: 210. DB::NetException: Connection reset by peer, while writing to socket" Also '/ping' is flavored from docs.Amortization

© 2022 - 2024 — McMap. All rights reserved.