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
Copy file name to clipboardExpand all lines: build/building/multi-stage.md
+75Lines changed: 75 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -205,3 +205,78 @@ RUN g++ -o /binary source.cpp
205
205
## Version compatibility
206
206
207
207
Multi-stage build syntax was introduced in Docker Engine 17.05.
208
+
209
+
## Differences between legacy build and BuildKit
210
+
211
+
The legacy Docker Engine builder processes all stages of a Dockerfile leading up to the selected `--target`. It will build a stage even if the selected target doesn't depend on that stage.
212
+
213
+
BuildKit only builds the stages that the target stage depends on.
214
+
215
+
For example, given the following Dockerfile:
216
+
217
+
```dockerfile
218
+
# syntax=docker/dockerfile:1
219
+
FROM ubuntu AS base
220
+
RUN echo "base"
221
+
222
+
FROM base AS stage1
223
+
RUN echo "stage1"
224
+
225
+
FROM base AS stage2
226
+
RUN echo "stage2"
227
+
```
228
+
229
+
With BuildKit enabled, building the `stage2` target in this Dockerfile means only `base` and `stage2` are processed. There is no dependency on `stage1`, so it's skipped.
0 commit comments