0
0
Dockerdevops~5 mins

Named build stages in Docker - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a named build stage in Docker?
A named build stage is a part of a Dockerfile where you give a name to a build step. This helps you reuse or copy files from that stage later in the build process.
Click to reveal answer
beginner
How do you name a build stage in a Dockerfile?
You name a build stage by adding AS <name> after the FROM instruction, like FROM node:18 AS builder.
Click to reveal answer
intermediate
Why use named build stages in Docker?
Named build stages let you create multi-step builds. You can build your app in one stage and copy only the needed files to the final image, making it smaller and cleaner.
Click to reveal answer
beginner
How do you copy files from a named build stage?
Use COPY --from=<stage-name> <source> <destination> to copy files from a named stage to the current stage.
Click to reveal answer
beginner
Example: What does this line do? <br>FROM python:3.12 AS builder
It starts a build stage named 'builder' using the Python 3.12 image. You can refer to this stage later to copy files or build on it.
Click to reveal answer
How do you name a build stage in a Dockerfile?
ARUN stage-name FROM image
BFROM image AS stage-name
CCOPY stage-name FROM image
DSTAGE image AS stage-name
What is the main benefit of using named build stages?
ATo reuse build steps and reduce final image size
BTo avoid using Docker Compose
CTo run containers faster
DTo make the Dockerfile longer
Which command copies files from a named build stage?
ACOPY --from=stage-name source destination
BRUN --from=stage-name source destination
CFROM --copy=stage-name source destination
DADD --from=stage-name source destination
Can you have multiple named build stages in one Dockerfile?
ANo, only one stage is allowed
BOnly two stages are allowed
CYes, you can have many named stages
DStages cannot be named
What happens if you don’t name a build stage?
AYou cannot build the image
BThe build will be faster
CDocker will name it automatically as 'default'
DThe stage is unnamed and can’t be referenced later
Explain what named build stages are and why they are useful in Docker.
Think about how you can split building and packaging in steps.
You got /3 concepts.
    Describe how to copy files from one build stage to another using named build stages.
    Focus on the COPY command with --from option.
    You got /3 concepts.