Using Docker Compose, how do you define that one service is dependent on another service?

Experience Level: Senior
Tags: Docker Compose

Answer

To define a dependency (or more dependencies), add the depends_on: property under you service:

version: "3.9"
services:
  web:
    image: busybox
    depends_on:
    - db
  db:
    image: busybox

This tells Docker Compose that the service web is dependent on the service db, so it will be started after the db service starts.

Comments

No Comments Yet.
Be the first to tell us what you think.
Docker Compose
Docker Compose

Are you learning Docker Compose ? Try our test we designed to help you progress faster.

Test yourself