Recall & Review
beginner
What is a multi-stage build in Docker?
A multi-stage build is a Docker feature that lets you use multiple FROM statements in one Dockerfile. It helps create smaller images by copying only the needed parts from earlier stages to the final image.
Click to reveal answer
beginner
Why use multi-stage builds?
Multi-stage builds reduce the final image size and improve security by excluding build tools and temporary files from the final image.
Click to reveal answer
intermediate
How do you copy files from one stage to another in a multi-stage build?
You use the COPY --from= command to copy files from a previous build stage to the current stage.
Click to reveal answer
intermediate
Give an example of a simple multi-stage Dockerfile.
Example:
FROM golang:1.20 AS builder
WORKDIR /app
COPY . .
RUN go build -o myapp
FROM alpine:latest
COPY --from=builder /app/myapp /myapp
CMD ["/myapp"]
Click to reveal answer
beginner
What happens if you don’t use multi-stage builds for compiled applications?
Without multi-stage builds, the final image may include unnecessary build tools and source files, making it larger and less secure.
Click to reveal answer
What is the main benefit of using multi-stage builds in Docker?
✗ Incorrect
Multi-stage builds help create smaller images by copying only necessary files to the final image.
How do you specify which stage to copy files from in a multi-stage build?
✗ Incorrect
The correct syntax to copy files from a previous stage is COPY --from=.
Which Dockerfile instruction starts a new build stage?
✗ Incorrect
Each FROM instruction starts a new build stage in a multi-stage Dockerfile.
What is a common use case for multi-stage builds?
✗ Incorrect
Multi-stage builds are often used to compile code in one stage and copy the final binary to a smaller image.
If you want to keep build tools out of the final image, what should you do?
✗ Incorrect
Multi-stage builds allow you to exclude build tools from the final image by separating build and runtime stages.
Explain how multi-stage builds help reduce Docker image size and improve security.
Think about separating build environment from runtime environment.
You got /4 concepts.
Describe the steps to create a multi-stage Dockerfile for a compiled application.
Focus on build and final stages.
You got /4 concepts.