Startup ordering and service readiness are different. A started database process may still be initializing.
Before you start
You should understand the difference between an image, a running container and the host. Record where a file, process or network endpoint actually lives before diagnosing a problem. Commands illustrate local experiments; adapt image names and paths to a disposable development environment.
The practical goal is to reason through this situation: Use an appropriate health condition and make the application resilient to temporary connection failures. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.
Step-by-step walkthrough
Step 1: Separate startup and readiness
A created database process may still be initializing.
Step 2: Use meaningful readiness
An appropriate health condition can gate initial startup where supported.
Step 3: Handle later interruptions
Applications must reconnect when a dependency restarts after startup.
Worked scenario
Use an appropriate health condition and make the application resilient to temporary connection failures.
Compose starts a database before the application, but database initialization takes longer. Initial connection still fails unless readiness and bounded retry are addressed. Even a successful initial health gate cannot prevent the database from restarting later, so operational connection recovery remains necessary.
Common mistake
A dependency declaration does not remove the need for runtime reconnection.
Verify the behavior
Test slow initialization and a dependency restart after the application is serving.
Interview exercise
Handle a restarted dependency.
Answer and reasoning
Retry eligible connections with bounds and observe readiness; do not rely only on initial startup order.
Continue learning
Compare the scenario with the Docker interview questions and test your understanding with the Docker MCQs. For terminology and implementation details, consult the reference material.