Challenge - 5 Problems
Builder Pattern Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2: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"]
Attempts:
2 left
💡 Hint
Consider how multi-stage builds isolate build artifacts from final image.
✗ Incorrect
The Dockerfile uses multi-stage build syntax correctly. The first stage named 'builder' installs dependencies and builds the app. The final stage copies only the built files from the builder stage, resulting in a smaller final image.
🧠 Conceptual
intermediate1:30remaining
Why use builder pattern before multi-stage builds?
Before Docker supported multi-stage builds, why was the builder pattern used in Dockerfiles?
Attempts:
2 left
💡 Hint
Think about how build tools and runtime environments differ.
✗ Incorrect
The builder pattern was used to keep build tools and dependencies separate from the final runtime image, reducing image size and attack surface.
❓ Troubleshoot
advanced2: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?
Attempts:
2 left
💡 Hint
Check if the build stage named 'builder' exists.
✗ Incorrect
The COPY --from=builder requires a build stage named 'builder'. Without 'AS builder' in the first FROM line, Docker cannot find the source stage.
✅ Best Practice
advanced1: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?
Attempts:
2 left
💡 Hint
Think about what files are necessary to run the app versus build it.
✗ Incorrect
Separating build and runtime environments keeps the final image small and secure by including only necessary runtime files.
🔀 Workflow
expert2: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:
Attempts:
2 left
💡 Hint
Consider what must be present before building and what is needed in the runtime.
✗ Incorrect
First install dependencies, then copy source code, then build, and finally copy artifacts to runtime container.