0
0
Dockerdevops~20 mins

Depends_on for service ordering in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Depends_on Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What does depends_on control in Docker Compose?

In a docker-compose.yml file, what is the main purpose of the depends_on key under a service?

AIt ensures the dependent service is fully ready before starting the current service.
BIt controls the order in which services start but does not wait for them to be ready.
CIt automatically restarts the dependent service if it crashes.
DIt links the network ports of the dependent service to the current service.
Attempts:
2 left
💡 Hint

Think about whether depends_on waits for the service to be fully ready or just starts it first.

💻 Command Output
intermediate
1:30remaining
Output of docker-compose with depends_on

Given this docker-compose.yml snippet:

version: '3.8'
services:
  db:
    image: postgres
  web:
    image: nginx
    depends_on:
      - db

What will happen when you run docker-compose up?

ABoth services start simultaneously without any order.
BThe <code>web</code> service waits until <code>db</code> is fully ready before starting.
CThe <code>db</code> service starts first, then <code>web</code> starts immediately after, without waiting for <code>db</code> readiness.
DThe <code>web</code> service will fail to start because <code>depends_on</code> is invalid syntax.
Attempts:
2 left
💡 Hint

Remember what depends_on controls in Docker Compose.

Configuration
advanced
2:00remaining
Correct depends_on syntax for multiple dependencies

Which depends_on syntax correctly specifies that a service depends on db and cache services?

Adepends_on: [db, cache]
B
depends_on:
  db: true
  cache: true
C
depends_on:
  db
  cache
D
depends_on:
  - db
  - cache
Attempts:
2 left
💡 Hint

Check the correct YAML list syntax for depends_on.

Troubleshoot
advanced
2:00remaining
Why does a service start before its dependency is ready?

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?

A<code>depends_on</code> only controls start order, not readiness or health checks.
B<code>depends_on</code> is deprecated and ignored by Docker Compose.
C<code>db</code> service is not exposed on the network, so <code>web</code> cannot connect.
D<code>web</code> service must be restarted manually after <code>db</code> is ready.
Attempts:
2 left
💡 Hint

Think about what depends_on does and does not guarantee.

Best Practice
expert
2:30remaining
How to ensure service readiness with depends_on in Docker Compose v3.8?

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?

AUse healthchecks in the dependency service and configure <code>depends_on</code> with condition: service_healthy.
BAdd a <code>restart: always</code> policy to the dependent service.
CManually add <code>sleep</code> commands in the dependent service's startup script.
DUse <code>links</code> instead of <code>depends_on</code> to enforce readiness.
Attempts:
2 left
💡 Hint

Check how Docker Compose can use healthchecks with depends_on conditions.