Recall & Review
beginner
What is a multi-stage Docker build?
A multi-stage Docker build uses multiple FROM statements in one Dockerfile to create intermediate images. This helps build smaller final images by copying only needed files from earlier stages.
Click to reveal answer
beginner
Why use multi-stage builds for different environments?
Multi-stage builds let you create separate stages for development, testing, and production in one Dockerfile. This keeps images optimized and environment-specific without repeating code.Click to reveal answer
intermediate
How do you specify which stage to use when building a Docker image?
Use the --target option with docker build to specify the stage name you want to build. For example: docker build --target production .
Click to reveal answer
intermediate
What is the benefit of copying files from one stage to another in a multi-stage build?
Copying files from one stage to another lets you separate build dependencies from runtime files. This reduces the final image size and improves security by excluding build tools.
Click to reveal answer
intermediate
Give an example of a simple multi-stage Dockerfile for development and production.
Example:
FROM node:18 AS development
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
FROM node:18 AS production
WORKDIR /app
COPY --from=development /app .
RUN npm prune --production
CMD ["node", "server.js"]
Click to reveal answer
What does the --target option do in a multi-stage Docker build?
✗ Incorrect
The --target option tells Docker which stage in the Dockerfile to build, allowing you to build only a specific environment stage.
Why are multi-stage builds useful for production images?
✗ Incorrect
Multi-stage builds help create smaller images by excluding unnecessary build tools and files, making production images optimized.
In a multi-stage Dockerfile, how do you copy files from a previous stage?
✗ Incorrect
The syntax COPY --from=stage_name copies files from a named build stage to the current stage.
Which of these is NOT a benefit of multi-stage builds?
✗ Incorrect
Multi-stage builds can make Dockerfiles longer but more organized; they do not necessarily simplify by combining all steps.
What base image is commonly used for Node.js multi-stage builds?
✗ Incorrect
The node:18 image is a common official Node.js base image used in multi-stage builds for Node.js apps.
Explain how multi-stage Docker builds help manage different environments like development and production.
Think about how you can build once but get different images for dev and prod.
You got /5 concepts.
Describe the steps to create a multi-stage Dockerfile for a Node.js app with development and production stages.
Focus on what happens in each stage and how they connect.
You got /6 concepts.