Bird
0
0

You have a Docker Compose file with a Django app and PostgreSQL service. How do you ensure the Django app waits for the database to be ready before starting?

hard📝 Application Q9 of 15
Django - Deployment and Production
You have a Docker Compose file with a Django app and PostgreSQL service. How do you ensure the Django app waits for the database to be ready before starting?
AUse a wait-for script or healthchecks in the Compose file
BSet depends_on to delay the app start indefinitely
CExpose ports only on the database service
DBuild the Django image after the database image
Step-by-Step Solution
Solution:
  1. Step 1: Understand service dependencies

    depends_on only controls start order but not readiness; a wait-for script or healthchecks ensure the database is ready before Django starts.
  2. Step 2: Evaluate other options

    depends_on does not wait indefinitely, exposing ports doesn't control startup, and build order doesn't affect runtime readiness.
  3. Final Answer:

    Use a wait-for script or healthchecks in the Compose file -> Option A
  4. Quick Check:

    Wait-for scripts ensure service readiness [OK]
Quick Trick: Use healthchecks or wait-for scripts to sync services [OK]
Common Mistakes:
MISTAKES
  • Assuming depends_on waits for readiness
  • Thinking port exposure controls startup order
  • Believing build order affects runtime dependencies

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes