-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Description
Description
Hey folks,
I’d like to bring up a long-standing feature request, originally from issue #6093, which dates back over five years. Since then, development practices have advanced, including enabling services to interact with each other during the docker-compose build
step.
The problem is still a major pain point: it's impossible for a service's build process to depend on other services in the same Compose file being up and running (unless you start them one by one).
The Proposal: build.depends_on
Let's add a depends_on
key inside the build
block. It's declarative, simple, and fits right into the existing Compose structure IMO.
services:
frontend:
build:
context: ./frontend
# THIS IS THE NEW PART
depends_on:
- database
# This is the existing runtime dependency
depends_on:
- database
database:
image: mongo:latest
# ...
How it would work:
- You run
docker-compose build frontend
. - Compose sees
build.depends_on: [database]
. - It spins up the
database
service first. - It then runs the
frontend
build. The build container can now successfully fetch data fromhttp://database:27017
. - When the build finishes (success or fail), Compose automatically tears down the
database
service.
No more build.sh
wrappers or makefiles. It's all self-contained in the compose.yml
.
Why this is a huge deal
This isn't an edge case anymore; it's central to many modern workflows.
-
Static Site Generators (Next.js, Gatsby, Astro): You need to build your static site by pulling content from a headless CMS (like PayloadCMS or a custom API) running in another container. Right now, this is impossible without a wrapper script or makefile.
-
API Client Generation: Your
frontend
build needs to generate a TypeScript client by hitting the/openapi.json
endpoint of yourbackend
service. The build fails because the backend isn't running. -
Database-driven builds: You want to bake something into your image that requires a live DB connection, like generating models from a schema or pre-populating a search index.
The Bottom Line
Adding build.depends_on
would be a massive quality-of-life improvement. It solves a real, common problem. It makes Compose a more complete tool for modern webdevelopment.
Would love to get this on the roadmap. What do you all think?