You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Usage of additional_contexts with the service: directive should imply build time dependencies #12783
The new service: directive for additional_contexts almost fulfills the dream of letting docker/docker-compose become highly usable in a monorepo scenario, where images depend on other images built on demand in the same repository. See https://stackoverflow.com/a/79487072/95653 for an 8-year-old question in that direction finally getting an answer.
However, the build time dependency created by the additional context is not represented anywhere, and as a result, most commands break. Please review the example below, which is adapted from the aforementioned Stack Overflow answer.
If you run docker compose build, everything works as expected. However, if I do docker compose build b, I get failed to find target a. The problem can be easily understood by running docker compose config b, which will show that service a does not exist in the configuration when you specify b explicitly.
There is an ugly workaround, which is using a depends_on for creating a runtime dependency, which will force a into the config when b is specified explicitly. This will let me do docker compose run --build b, but it will startup both service b and a, and I although I think it is reasonable to want b, I usually do not want a. One can start to play with more workarounds, like adding a parallel tree of build dependencies with a no-op entrypoint, but everything starts to get cumbersome and you start to hit other bugs.
Everything would work out of the box if docker compose config b brought a into the config, but somehow managed to mark it as not to start.
Going further down, once this is fixed, the build time dependency graph should also be exposed to docker compose watch, but I guess that goes as a different bug later.
Thanks a lot for the fix. Running docker compose build b now works fine, but docker compose run --build b and docker compose up --build b still fail, each one with a different error. Enabling COMPOSE_BAKE yields a third error message.
pkgx [email protected] docker-compose up --build b
Compose can now delegate builds to bake for better performance.
To do so, set COMPOSE_BAKE=true.
[+] Building 0.0s (1/1) FINISHED docker:desktop-linux
=> [b internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 88B 0.0s
failed to solve: invalid reference format
COMPOSE_BAKE=true pkgx [email protected] docker-compose up --build b
[+] Building 0.0s (1/1) FINISHED
=> [internal] load local bake definitions 0.0s
=> => reading from stdin 442B 0.0s
failed to find target a
pkgx [email protected] docker-compose run --build b
no such service: a
Activity
ndeloof commentedon Apr 28, 2025
requalified as a bug, my earlier fix for this was incomplete
davireis commentedon May 8, 2025
Hi @ndeloof , @glours ,
Thanks a lot for the fix. Running
docker compose build bnow works fine, butdocker compose run --build banddocker compose up --build bstill fail, each one with a different error. Enabling COMPOSE_BAKE yields a third error message.