[BUG] additional_contexts
for builds with references to other services not working as documented
#12579
Labels
additional_contexts
for builds with references to other services not working as documented
#12579
Description
Hi,
I am currently building a compose project making use of the
service:<service_name>
syntax in theadditional_contexts
list of my build context (link to corresponding docs).Note that the example given in the documentation fails because the service
base
cannot be defined twice. I therefore renamed the second service.I'd expect this to work fine, but
docker compose build
ends up not finding the corresponding image, i.e., I getfailed to solve: base: failed to resolve source metadata for docker.io/library/base:latest
.I'll add the minimal
compose.yaml
for reproduction in the steps to reproduce, and provide a suggestion on how to either fix this issue or, if my suggestion is not easily feasible from a technical perspective, on how to update the documentation.Thanks in advance!
Steps To Reproduce
compose.yaml
in/tmp/compose.yaml
:docker compose build
orsudo docker compose build
, depending on whether your user is in thedocker
group or notA working
compose.yaml
:Note the additional
image: base
key.My observation is as follows:
The
additional_contexts
value, i.e., theservice:base
only needs to refer to the correct service.However, the corresponding key, i.e., the
base
needs to refer to the corresponding service's image name.If no image name and project name is defined,
docker compose
derives the project name from the working directory and therefore also the image names.In this specific instance (project directory
/tmp
), this means that the followingcompose.yaml
builds fine:Note the
tmp-base
in thederived
service. This behavior is not exactly intuitive, and requires to always be aware of the project name.Suggestions
On the technical side, this problem could be resolved by the key, i.e.,
base
/tmp-base
not requiring to be the same as the base service's image name.More specifically, the chosen key (which could also lead to
asdasdasd: service:base
instead ofbase: service:base
) becomes an alias to the corresponding image name internally (with this example:asdasdasd
becomes an alias fortmp-base
).This behavior would be the most intuitive but I don't know enough about the compose internals to judge its feasibility.
Otherwise, this behavior could be explicitly documented, pointing out that a user has to either
tmp-base
), orimage: base
).In my opinion, a technical solution would be better than a solution on the documentation side because the project-specific image name is not necessarily portable and the explicit image name for the base image might collide with image names in the global namespace.
Compose Version
Docker Environment
Anything else?
No response
The text was updated successfully, but these errors were encountered: