During an automated staging deploy, Docker Compose began tearing down newly started containers before they could finish running database migrations, causing a persistent deploy restart loop.
services:
app:
image: turkerdev/app:latest
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/health"]
interval: 10s
timeout: 5s
retries: 3
# Crucial: provide grace period for boot and migrations
start_period: 40s
Without start_period, health check failures during the first thirty seconds counted toward the retry threshold. Adding a forty-second start period gives migration scripts time to complete before health check failures are considered fatal.