@@ -138,6 +138,22 @@ volumes:
138138 labels :
139139 description : " Spring Boot application logs"
140140
141+ # Volume for Keycloak data (build configuration and cache)
142+ keycloak-conf :
143+ driver : local
144+ labels :
145+ description : " Keycloak build configuration"
146+ backup : " recommended"
147+ critical : " false"
148+
149+ # Volume for Keycloak runtime data (cache, temporary files)
150+ keycloak-lib :
151+ driver : local
152+ labels :
153+ description : " Keycloak runtime data"
154+ backup : " recommended"
155+ critical : " false"
156+
141157# ============================================================================
142158# SECRETS
143159# ============================================================================
@@ -170,7 +186,7 @@ services:
170186 nginx :
171187 image : nginx:1.29-alpine
172188 container_name : nginx
173-
189+
174190 # Drop all capabilities (principle of least privilege)
175191 cap_drop :
176192 - ALL
@@ -184,6 +200,9 @@ services:
184200 security_opt :
185201 - no-new-privileges:true # Prevent escalation
186202
203+ env_file :
204+ - env_files/.env.nginx
205+
187206 # Restart policy
188207 restart : unless-stopped
189208
@@ -268,6 +287,9 @@ services:
268287 networks :
269288 - backend
270289
290+ extra_hosts :
291+ - " mcqueide.local:172.21.0.1"
292+
271293 # Ports: DO NOT expose externally in production
272294 # ports:
273295 # - "8081:8080" # ❌ For debug only, remove in production
@@ -276,9 +298,8 @@ services:
276298 expose :
277299 - " 8080"
278300
279- # Not required, docker uses .env by default
280301 env_file :
281- - .env
302+ - env_files/ .env.api
282303
283304 secrets :
284305 - api-db-password
@@ -383,7 +404,7 @@ services:
383404
384405 # Not required, docker uses .env by default
385406 env_file :
386- - .env
407+ - env_files/ .env.db
387408
388409 # OPTIMIZATION: Use tmpfs for temporary data (improves performance)
389410 # Sockets and temp files don't require persistence
@@ -393,7 +414,7 @@ services:
393414
394415 # Healthcheck
395416 healthcheck :
396- test : [ "CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}" ]
417+ test : [ "CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres } -d ${POSTGRES_DB:-postgres }" ]
397418 interval : 10s
398419 timeout : 5s
399420 retries : 5
@@ -455,11 +476,15 @@ services:
455476 - keycloak-admin-password
456477
457478 env_file :
458- - .env
479+ - env_files/ .env.keycloak
459480
460481 volumes :
482+ - keycloak-conf:/opt/keycloak/conf
483+ - keycloak-lib:/opt/keycloak/lib/quarkus/
461484 - ./keycloak/export:/opt/keycloak/data/import
462485
486+ # NOTE: Use 'start' for production (builds automatically on first run)
487+ # After first successful build, you can optionally use 'start --optimized' for faster restarts
463488 command : start-dev
464489
465490 # Run import
@@ -470,7 +495,7 @@ services:
470495 condition : service_healthy
471496
472497 healthcheck :
473- test : ["CMD-SHELL", "exec 3<>/dev/tcp/keycloak/9000 && echo -e 'GET /health/ready HTTP/1.1\r\nHost: keycloak\r\nConnection: close\r\n\r\n' >&3 && cat <&3 | grep -q '200 OK'"]
498+ test : ["CMD-SHELL", "exec 3<>/dev/tcp/keycloak/9000 && echo -e 'GET /auth/ health/ready HTTP/1.1\r\nHost: keycloak\r\nConnection: close\r\n\r\n' >&3 && cat <&3 | grep -q '200 OK'"]
474499 interval : 30s
475500 timeout : 10s
476501 retries : 5
@@ -480,10 +505,10 @@ services:
480505 resources :
481506 limits :
482507 cpus : ' 0.5'
483- memory : 512M
508+ memory : 768M
484509 reservations :
485510 cpus : ' 0.25'
486- memory : 256M
511+ memory : 512M
487512
488513 logging :
489514 driver : " json-file"
@@ -513,7 +538,7 @@ services:
513538 - keycloak-admin-password
514539
515540 env_file :
516- - .env
541+ - env_files/ .env.keycloak
517542
518543 volumes :
519544 - ./keycloak/export:/opt/keycloak/data/import:rw
@@ -543,10 +568,6 @@ services:
543568# Deploy with minimal downtime:
544569# docker compose up -d --no-deps --build app
545570#
546- # Check service health:
547- # docker compose ps
548- # docker compose exec app node healthcheck.js
549- #
550571# Logs:
551572# docker compose logs -f app
552573# docker compose logs --tail=100 postgres
0 commit comments