Challenges
Missing Health Check
The app container boots before Postgres is ready. Add a healthcheck so depends_on can use condition: service_healthy.
The Problem
Your docker-compose.yml has a depends_on: db directive in the app service.
But depends_on only waits for the db container's process to start. It doesn't wait for Postgres to finish booting up and accepting connections.
If you run docker compose up, your PHP app will start instantly, try to connect to the database, and crash with a "Connection refused" error because Postgres is still initializing its data directory.
To fix this, you must tell Docker how to check if Postgres is healthy, and tell the app to wait for that health status.
What You Need to Fix
Load this challenge:
php artisan challenge:start docker-missing-healthcheckThe docker-compose.yml file is copied to your project root.
- Add a
healthcheckblock to thedbservice. Usepg_isready -U postgresas the test command. - Update the
depends_onblock in theappservice. It currently uses the short array syntax (- db). Change it to the object syntax and addcondition: service_healthy.
Hints
- A Postgres healthcheck looks like this:
healthcheck: test: ["CMD-SHELL", "pg_isready -U postgres"] interval: 5s timeout: 5s retries: 5 - The long syntax for
depends_onlooks like this:depends_on: db: condition: service_healthy
Verify
php artisan challenge:verify