CodePark/ questions / Multi-stage builds & image size
START PRACTICINGPRACTICE
Backend question · Docker › Multi-stage builds & image size

A Dockerfile has stages deps, build, test and a final unnamed stage. What does docker build --target build -t app:build . do with BuildKit?

Builds the build stage and only the stages it depends on, then stops

--target stops at the named stage. BuildKit (Docker's modern builder) skips any stage that the target does not depend on. So it builds build and the stages it needs, and it does not build test or the final stage.

The old legacy builder processed all stages up to the target. That is why many people believe "Builds every stage, then tags the
build stage". With BuildKit, that is wrong.