Challenge 2: Fix a depends_on Race Condition — Possible Solution ==================================================================== DIAGNOSIS: this is the classic depends_on race condition this chapter described. Plain depends_on: [db] only waits for the db CONTAINER to start — it says nothing about whether the database software running inside it has finished its own startup process and is actually accepting connections yet. Because database startup (initializing data files, running startup checks) genuinely takes some variable amount of time, api sometimes wins the race and tries to connect before db is truly ready — producing the intermittent (not constant) "connection refused" behavior described, since the exact timing varies build to build. THE FIX: services: db: image: mysql:8 healthcheck: test: ["CMD", "mysqladmin", "ping", "-h", "localhost"] interval: 5s retries: 10 start_period: 30s api: depends_on: db: condition: service_healthy Adding a healthcheck to db gives Compose a real way to know when MySQL is actually ready (not just running), and changing api's depends_on to condition: service_healthy means api won't even start until that healthcheck passes — closing the race condition entirely, rather than just making it statistically less likely with an arbitrary delay.