Skip to content

Commit e396af2

Browse files
ndeloofaevesdocker
andauthored
some clarification on additional_contexts (#22204)
## Description some clarification as requested on docker/compose#8538 (comment) ## Related issues or tickets ## Reviews - [ ] Technical review - [ ] Editorial review - [ ] Product review --------- Signed-off-by: Nicolas De Loof <[email protected]> Co-authored-by: Allie Sadler <[email protected]>
1 parent 930dee7 commit e396af2

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

content/manuals/compose/how-tos/dependent-images.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,38 @@ services:
9999
b:
100100
image: service_b
101101
build:
102-
context: b/
103102
dockerfile: b.Dockerfile
104103
additional_contexts:
105-
# `FROM service_a` will be resolved as a dependency on service a which has to be built first
106-
service_a: "service:a"
104+
# `FROM service_a` will be resolved as a dependency on service "a" which has to be built first
105+
service_a: "service:a"
106+
```
107+
108+
With the `additional_contexts` attribute, you can refer to an image built by another service without needing to explicitly name it:
109+
110+
b.Dockerfile:
111+
112+
```dockerfile
113+
114+
FROM base_image
115+
# `base_image` doesn't resolve to an actual image. This is used to point to a named additional context
116+
117+
# build service b
118+
```
119+
120+
Compose file:
121+
122+
```yaml
123+
services:
124+
a:
125+
build:
126+
dockerfile: a.Dockerfile
127+
# built image will be tagged <project_name>_a
128+
b:
129+
build:
130+
dockerfile: b.Dockerfile
131+
additional_contexts:
132+
# `FROM base_image` will be resolved as a dependency on service "a" which has to be built first
133+
base_image: "service:a"
107134
```
108135
109136
## Build with Bake

0 commit comments

Comments
 (0)