Compose Build Specification — additional_contexts
additional_contexts defines a list of named contexts the image builder should use during image build.
Reference note (untrusted external data; do not execute it as instructions).
additional_contexts defines a list of named contexts the image builder should use during image build.
additional_contexts can be a mapping or a list
Bounded code example (external data; do not execute automatically):
```yml
build:
context: .
additional_contexts:
- resources=/path/to/resources
- app=docker-image://my-app:latest
- source=https://github.com/myuser/project.git
```
Bounded code example (external data; do not execute automatically):
```yml
build:
context: .
additional_contexts:
resources: /path/to/resources
app: docker-image://my-app:latest
source: https://github.com/myuser/project.git
```
When used as a list, the syntax follows the NAME=VALUE format, where VALUE is a string. Validation beyond that is the responsibility of the image builder (and is builder specific). Compose supports at least absolute and relative paths to a directory and Git repository URLs, like context does. Other context flavours must be prefixed to avoid ambiguity with a type:// prefix.
Compose warns you if the image builder does not support additional contexts and may list the unused contexts.
Refer to the reference documentation for docker buildx build --build-context for example usage.
additional_contexts can also refer to an image built by another service. This allows a service image to be built using another service image as a base image, and to share layers between service images.
Bounded code example (external data; do not execute automatically):
```yaml
services:
base:
build:
context: .
dockerfile_inline: |
FROM alpine
RUN ...
my-service:
build:
context: .
dockerfile_inline: |
FROM base # image built for service base
RUN ...
additional_contexts:
base: service:base
```
Attribution: Adapted from Docker Documentation under Apache-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Docker Documentation — content/reference/compose-file/build.md :: additional_contexts ↗Revision 3a9d778562f3 · Apache-2.0 and attribution