Use depends_on in a Docker Compose service definition when one service must start after other services. Compose starts the listed dependencies before starting the dependent service. section 7.2
Listing 7.2 Compose services for the multi-container app
accesslog:
image: diamol/ch04-access-log:2e
iotd:
image: diamol/ch04-image-of-the-day:2e
ports:
- "80"
image-gallery:
image: diamol/ch04-image-gallery:2e
ports:
- "8010:80"
depends_on:
- accesslog
- iotd
See the multi-container Compose definition where image-gallery depends on accesslog and iotd. section 7.2
Apply the dependency in a runnable Compose workflow:
- Declare the required service names under depends_on. section 7.2
- Start the application with docker compose up --detach. section 7.2
- Verify that dependencies start before the dependent service and browse the application on its published host port. section 7.2
