In a docker-compose.yml file, what is the main purpose of the depends_on key under a service?
Think about whether depends_on waits for the service to be fully ready or just starts it first.
The depends_on key only controls the start order of services. It does not wait for the dependent service to be fully ready or healthy before starting the next one.
Given this docker-compose.yml snippet:
version: '3.8'
services:
db:
image: postgres
web:
image: nginx
depends_on:
- dbWhat will happen when you run docker-compose up?
Remember what depends_on controls in Docker Compose.
depends_on ensures db starts before web, but web does not wait for db to be ready.
Which depends_on syntax correctly specifies that a service depends on db and cache services?
Check the correct YAML list syntax for depends_on.
The correct syntax uses a YAML list with dashes for each service dependency.
You have a web service that depends_on a db service. However, web tries to connect to db before it is ready, causing errors. Why does this happen?
Think about what depends_on does and does not guarantee.
depends_on only ensures the db service starts before web, but it does not wait for db to be ready or healthy.
Docker Compose's depends_on does not wait for service readiness. What is the best way to ensure a service starts only after its dependency is fully ready?
Check how Docker Compose can use healthchecks with depends_on conditions.
In Docker Compose version 3.4 and above, you can use healthchecks and specify condition: service_healthy in depends_on to wait for readiness.