0
0
Dockerdevops~20 mins

Builder pattern before multi-stage in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Builder Pattern Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of multi-stage build simulation using builder pattern
Given the Dockerfile below simulating a builder pattern before multi-stage builds, what will be the output when running docker build .?
Docker
FROM node:18 AS builder
WORKDIR /app
COPY package.json ./
RUN npm install
COPY . ./
RUN npm run build

FROM node:18
WORKDIR /app
COPY --from=builder /app/dist ./dist
CMD ["node", "dist/index.js"]
ABuild succeeds but final image contains all source files and node_modules
BBuild fails due to COPY --from=builder syntax not supported before multi-stage
CBuild succeeds and final image contains only /app/dist with built files
DBuild fails because npm install is not run in final stage
Attempts:
2 left
💡 Hint
Consider how multi-stage builds isolate build artifacts from final image.
🧠 Conceptual
intermediate
1:30remaining
Why use builder pattern before multi-stage builds?
Before Docker supported multi-stage builds, why was the builder pattern used in Dockerfiles?
ATo separate build dependencies from runtime dependencies and reduce final image size
BTo enable parallel builds of multiple images simultaneously
CTo allow running multiple containers from the same image
DTo automatically update base images during build
Attempts:
2 left
💡 Hint
Think about how build tools and runtime environments differ.
Troubleshoot
advanced
2:00remaining
Troubleshooting COPY --from error in Dockerfile
You have this Dockerfile simulating a builder pattern before multi-stage builds:
FROM node:18
WORKDIR /app
COPY package.json ./
RUN npm install
COPY . ./
RUN npm run build

COPY --from=builder /app/dist ./dist
CMD ["node", "dist/index.js"]
What error will Docker produce when building this Dockerfile?
AError: unknown flag: --from
BError: missing 'AS builder' stage declaration
CNo error, build completes successfully
DError: COPY failed: stat /app/dist: no such file or directory
Attempts:
2 left
💡 Hint
Check if the build stage named 'builder' exists.
Best Practice
advanced
1:30remaining
Best practice for reducing final image size with builder pattern
Which approach best reduces the final Docker image size when using a builder pattern before multi-stage builds?
AUse a separate build container to compile artifacts, then copy only artifacts into a minimal runtime image
BUse a single Dockerfile stage with all build and runtime steps combined
CInstall all dependencies in the final image to avoid missing packages
DInclude source code and node_modules in the final image for debugging
Attempts:
2 left
💡 Hint
Think about what files are necessary to run the app versus build it.
🔀 Workflow
expert
2:30remaining
Order of steps in builder pattern Dockerfile before multi-stage
Arrange the following Dockerfile steps in the correct order to implement a builder pattern before multi-stage builds:
A1,3,2,4
B1,2,3,4
C2,3,1,4
D2,1,3,4
Attempts:
2 left
💡 Hint
Consider what must be present before building and what is needed in the runtime.