Reputation: 190
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?
Upvotes: 11
Views: 5648
Reputation: 2246
Solution for this version v0.41.1
For some reason localhost is not resolved. Use the IP 127.0.0.1.
CONTAINER REPOSITORY TAG IMAGE ID SIZE
otel-migrator signoz/signoz-schema-migrator 0.88.15 b83632b02639 29.1MB
signoz-alertmanager signoz/alertmanager 0.23.5 61e8cf1e8ddf 61MB
signoz-clickhouse clickhouse/clickhouse-server 24.1.2-alpine ccae8bc2d860 882MB
signoz-frontend signoz/frontend 0.41.1 702939f4533d 61.9MB
signoz-logspout gliderlabs/logspout v3.2.14 8584e170d2ab 32.6MB
signoz-otel-collector signoz/signoz-otel-collector 0.88.15 c387d1384cfb 182MB
signoz-query-service signoz/query-service 0.41.1 41bebb88cba6 57.6MB
signoz-zookeeper-1 bitnami/zookeeper 3.7.1 3ab0e8f032ab 510MB
docker-compose.yaml:
...
x-clickhouse-defaults: &clickhouse-defaults
restart: on-failure
# addding non LTS version due to this fix https://github.com/ClickHouse/ClickHouse/commit/32caf8716352f45c1b617274c7508c86b7d1afab
image: clickhouse/clickhouse-server:24.1.2-alpine
tty: true
depends_on:
- zookeeper-1
# - zookeeper-2
# - zookeeper-3
logging:
options:
max-size: 50m
max-file: "3"
healthcheck:
# "clickhouse", "client", "-u ${CLICKHOUSE_USER}", "--password ${CLICKHOUSE_PASSWORD}", "-q 'SELECT 1'"
test: wget --no-verbose --tries=1 http://127.0.0.1:8123/ping || exit 1
interval: 10s
timeout: 10s
retries: 3
...
Test / Justification:
/ # ping localhost -c 3
PING localhost (::1): 56 data bytes
64 bytes from ::1: seq=0 ttl=64 time=0.051 ms
64 bytes from ::1: seq=1 ttl=64 time=0.042 ms
64 bytes from ::1: seq=2 ttl=64 time=0.047 ms
--- localhost ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.042/0.046/0.051 ms
/ # wget --no-verbose --tries=1 --spider http://localhost:8123/ping
Connecting to localhost:8123 ([::1]:8123)
wget: can't connect to remote host: Connection refused
/ # wget --no-verbose --tries=1 --spider http://::1:8123/ping
Connecting to ::1:8123 ([::1:8123]:80)
wget: can't connect to remote host: Network unreachable
/ # wget --no-verbose --tries=1 --spider http://127.0.0.1:8123/ping
Connecting to 127.0.0.1:8123 (127.0.0.1:8123)
remote file exists
Upvotes: 3
Reputation: 15226
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
..
Upvotes: 15