Recall & Review
beginner
What is a multi-stage build in Docker?
A multi-stage build lets you use multiple FROM statements in one Dockerfile. Each stage can build parts of the app, and you can copy only the needed parts to the final image. This keeps the image small and clean.
Click to reveal answer
beginner
How do you name a stage in a Dockerfile?
You name a stage by adding 'AS ' after the FROM instruction. For example: FROM node:18 AS builder names the stage 'builder'.
Click to reveal answer
intermediate
How can you copy files from a specific stage in a multi-stage Docker build?
Use the COPY --from= command to copy files from a named stage. For example: COPY --from=builder /app/build /app copies files from the 'builder' stage.
Click to reveal answer
intermediate
Why target a specific stage when building a Docker image?
Targeting a specific stage lets you build only part of the Dockerfile. This is useful for testing or debugging intermediate stages without building the whole image.
Click to reveal answer
beginner
What is the Docker build command option to target a specific stage?
Use the --target option with docker build to specify which stage to build. For example: docker build --target builder -t myapp:builder . builds only the 'builder' stage.
Click to reveal answer
What does the 'AS' keyword do in a Dockerfile multi-stage build?
✗ Incorrect
The 'AS' keyword names a build stage so you can reference it later.
How do you copy files from a previous stage named 'builder'?
✗ Incorrect
COPY --from=builder copies files from the 'builder' stage.
Which docker build option lets you build only a specific stage?
✗ Incorrect
The --target option specifies which stage to build.
Why use multi-stage builds in Docker?
✗ Incorrect
Multi-stage builds help reduce image size by copying only necessary files.
What happens if you don't specify --target when building a multi-stage Dockerfile?
✗ Incorrect
By default, Docker builds the last stage in the Dockerfile.
Explain how to use multi-stage builds to keep Docker images small.
Think about building in steps and copying only what you need.
You got /4 concepts.
Describe how to build only a specific stage in a Dockerfile.
Focus on the docker build command options.
You got /3 concepts.