0
0
Dockerdevops~5 mins

Multi-stage for different environments in Docker - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ASpecifies which build stage to build
BSets the base image for the build
CDefines the output image name
DRuns the container after build
Why are multi-stage builds useful for production images?
AThey run faster on all machines
BThey include all development tools
CThey create smaller, optimized images
DThey automatically update dependencies
In a multi-stage Dockerfile, how do you copy files from a previous stage?
ARUN copy stage_name source destination
BADD --stage=stage_name source destination
CCOPY source destination
DCOPY --from=stage_name source destination
Which of these is NOT a benefit of multi-stage builds?
ASeparate build and runtime environments
BSimplifies Dockerfile by combining all steps
CSmaller final image size
DImproves security by excluding build tools
What base image is commonly used for Node.js multi-stage builds?
Anode:18
Bpython:3.12
Cubuntu:latest
Dalpine:latest
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.