Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Check if clickhouse is healthy docker-compose

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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
    ..
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading