Skip to content

Commit 680cb17

Browse files
vharmainclaude
andcommitted
Add Docker health checks for reliable startup ordering
Nginx proxy can fail when backend isn't ready yet because `links` only ensures DNS resolution, not service readiness. Add healthchecks to postgres (pg_isready), elasticsearch (cluster health), and backend (/api/health), then use `depends_on: condition: service_healthy` to enforce postgres+elasticsearch → backend → proxy startup order. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 59d6f67 commit 680cb17

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

docker-compose.yml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ services:
2121
proxy:
2222
extends:
2323
service: proxy-base
24+
depends_on:
25+
backend:
26+
condition: service_healthy
2427
links:
2528
- mapproxy
2629
- backend
@@ -35,9 +38,12 @@ services:
3538
proxy-dev:
3639
extends:
3740
service: proxy-base
41+
depends_on:
42+
backend:
43+
condition: service_healthy
3844
links:
3945
- mapproxy
40-
#- backend
46+
- backend
4147
- logstash
4248
- kibana
4349
- geoserver
@@ -163,6 +169,17 @@ services:
163169
extends:
164170
service: backend-base
165171
command: java -Duser.timezone=UTC -Xmx2G -jar backend.jar -m lipas.backend.system server
172+
healthcheck:
173+
test: ["CMD", "curl", "-f", "http://localhost:8091/api/health"]
174+
interval: 30s
175+
timeout: 5s
176+
retries: 3
177+
start_period: 60s
178+
depends_on:
179+
postgres:
180+
condition: service_healthy
181+
elasticsearch:
182+
condition: service_healthy
166183
ports:
167184
- '8091:8091'
168185
- '7888:7888'
@@ -304,6 +321,11 @@ services:
304321

305322
postgres:
306323
image: postgis/postgis:17-3.5
324+
healthcheck:
325+
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER"]
326+
interval: 10s
327+
timeout: 5s
328+
retries: 5
307329
environment:
308330
POSTGRES_USER: ${DB_SUPERUSER}
309331
POSTGRES_PASSWORD: ${DB_SUPERUSER_PASSWORD}
@@ -320,6 +342,12 @@ services:
320342

321343
elasticsearch:
322344
image: docker.elastic.co/elasticsearch/elasticsearch:8.19.9
345+
healthcheck:
346+
test: ["CMD-SHELL", "curl -sf http://localhost:9200/_cluster/health || exit 1"]
347+
interval: 30s
348+
timeout: 10s
349+
retries: 5
350+
start_period: 30s
323351
ports:
324352
- '9200:9200'
325353
- '9300:9300'
@@ -341,7 +369,8 @@ services:
341369
elasticsearch-setup:
342370
image: curlimages/curl:8.11.1
343371
depends_on:
344-
- elasticsearch
372+
elasticsearch:
373+
condition: service_healthy
345374
volumes:
346375
- "./elasticsearch/setup:/setup:z"
347376
environment:

0 commit comments

Comments
 (0)