Which explanation best describes why multi-stage builds help reduce the final Docker image size?
Think about how build tools and temporary files affect image size and what multi-stage builds let you do with them.
Multi-stage builds let you use multiple FROM statements. You can build your app in one stage with all tools, then copy only the final app files to a smaller base image. This excludes build tools and temporary files, reducing image size.
Given the following Dockerfile snippet, what will be the approximate size difference between the final image using multi-stage build versus a single-stage build?
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"]
Consider what files and tools are present in each stage and what is copied to the final image.
The builder stage includes the Go compiler and source code, which are large. The final stage copies only the compiled binary to a small Alpine base image, making the final image much smaller.
Which Dockerfile snippet correctly uses multi-stage builds to reduce image size by building a Node.js app and copying only the production files?
Look for copying only the build output and production dependencies, not the entire source.
Option C copies only the build output folder and node_modules from the build stage to the smaller base image. Option C copies the entire /app folder including source files, increasing size. Option C copies only package.json, missing build output. Option C is single-stage.
A developer uses a multi-stage Dockerfile to build a Java app but notices the final image is still very large and contains build tools. What is the most likely cause?
Think about what files are copied from the build stage to the final image.
If the entire build directory is copied, it includes build tools and temporary files, making the final image large. Only the compiled artifact (e.g., jar file) should be copied.
Which practice best helps minimize Docker image size when using multi-stage builds for a compiled language project?
Consider what files are essential to run the app and what can be left out.
Using a minimal base image and copying only the compiled binary and necessary config files keeps the final image small and efficient. Including build tools or source code increases size unnecessarily.