Improve Docker healthcheck to validate schema initialization

- Check for 'users' table existence instead of just mysqladmin ping
- Ensures schema.sql has executed before marking as healthy
- Add 40s start_period for initial schema load
- Prevents Spring Boot from connecting to uninitialized database
This commit is contained in:
2026-03-09 21:47:34 -06:00
parent 56bb4f19e8
commit a1be1a5688

View File

@@ -15,10 +15,11 @@ services:
- ./src/main/resources/schema.sql:/docker-entrypoint-initdb.d/01-schema.sql
- ./src/main/resources/data.sql:/docker-entrypoint-initdb.d/02-data.sql
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-uroot", "-proot"]
interval: 5s
test: ["CMD", "mysql", "-uroot", "-proot", "-e", "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='Petstoredb' AND table_name='users';"]
interval: 10s
timeout: 5s
retries: 30
start_period: 40s
volumes:
db_data: