这是indexloc提供的服务,不要输入任何密码
Skip to content

Add build.depends_on for build-time dependencies #13073

@Copystrike

Description

@Copystrike

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:

  1. You run docker-compose build frontend.
  2. Compose sees build.depends_on: [database].
  3. It spins up the database service first.
  4. It then runs the frontend build. The build container can now successfully fetch data from http://database:27017.
  5. 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 your backend 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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions