Given the following Dockerfile, what will be the output of docker build --target builder .?
FROM alpine AS builder RUN echo "Building stage" > /build.txt FROM alpine COPY --from=builder /build.txt /app/build.txt CMD cat /app/build.txt
When you specify --target builder, Docker stops after building that stage.
Using --target builder builds only up to the stage named 'builder'. The output shows the steps up to that stage, including the RUN command creating /build.txt. The final image is from the builder stage only.
Why would a developer use the --target option to build a specific stage in a multi-stage Dockerfile?
Think about testing or debugging parts of the build process.
Using --target allows building up to a specific stage. This helps developers test or debug intermediate stages without building the entire image.
Which Dockerfile snippet correctly defines two stages named builder and final so that you can target the builder stage during build?
Both stages must be named to use --target properly.
To target a stage, it must be named with AS <name>. Option C names both stages correctly, allowing --target builder to work.
What error will Docker show if you run docker build --target test . but the Dockerfile has no stage named test?
Docker complains when the target stage name is missing in the Dockerfile.
If the target stage does not exist, Docker returns an error like 'failed to build: stage 'test' not found'.
You have a multi-stage Dockerfile with stages builder, tester, and final. You want to run tests only on the tester stage without building the final stage. Which command achieves this?
Check the correct Docker CLI option for targeting a build stage.
The --target option specifies which stage to build up to. Using --target tester builds only up to the tester stage.