Interview Prep/Docker/Dockerfile Instructions & Builds

How do you build only one stage, or use a stage as a test target?

IntermediateConceptDockerfile Instructions & Builds
Answer

Use --target. Typical pattern: base, dev, test, prod stages in one file.

docker build --target test -t app:test .
docker build --target prod -t app:1.0 .

BuildKit only builds stages the target depends on, skipping unrelated ones.

All Docker questions Roadmap: Docker & containers

More on Dockerfile Instructions & Builds