0
0
Dockerdevops~20 mins

Development container patterns in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Development Container Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of multi-stage Docker build
Consider this Dockerfile using multi-stage build pattern:
FROM node:18 AS builder
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
RUN npm run build

FROM nginx:alpine
COPY --from=builder /app/build /usr/share/nginx/html
What will be the output when running docker images after building this Dockerfile with docker build -t myapp .?
AOnly the 'builder' image remains, tagged as 'myapp', containing all build layers
BTwo images: one intermediate 'builder' image and one final 'myapp' image with nginx and app files
CNo images are created because multi-stage builds do not produce images
DAn image named 'myapp' with a single layer containing only the nginx base and the built app files
Attempts:
2 left
💡 Hint
Multi-stage builds keep only the final stage as the image unless you tag intermediate stages.
Configuration
intermediate
2:00remaining
Correct Dockerfile pattern for caching dependencies
You want to optimize your Dockerfile to cache dependencies and avoid reinstalling them on every build. Which Dockerfile snippet correctly implements this pattern?
A
COPY . ./
RUN npm install
B
COPY package.json ./
RUN npm install
COPY . ./
C
RUN npm install
COPY package.json ./
COPY . ./
D
COPY . ./
RUN npm install
COPY package.json ./
Attempts:
2 left
💡 Hint
Think about which files change less often and how Docker caches layers.
Troubleshoot
advanced
2:00remaining
Why does my container fail to start with permission denied?
You have this Dockerfile snippet:
FROM python:3.12-slim
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
CMD ["python", "app.py"]

When running the container, you get a permission denied error on app.py. What is the most likely cause?
Aapp.py does not have execute permissions inside the container
BThe WORKDIR /app does not exist in the container
Cpip install failed and dependencies are missing
DThe CMD syntax is incorrect and causes failure
Attempts:
2 left
💡 Hint
Check file permissions inside the container for scripts.
🔀 Workflow
advanced
2:00remaining
Order of steps in a development container workflow
Arrange these steps in the correct order for a typical development container workflow:
1. Run the container interactively
2. Write or edit code on the host
3. Build the Docker image
4. Mount source code into the container
A4,1,2,3
B1,4,2,3
C1,2,4,3
D1,2,3,4
Attempts:
2 left
💡 Hint
Think about when you build, mount, and edit code during development.
Best Practice
expert
2:00remaining
Choosing the best base image for a development container
You want a development container for a Node.js app that is fast to build, small in size, and supports debugging tools. Which base image is the best choice?
Anode:18-slim
Bnode:18-alpine
Cnode:18-buster
Dnode:18
Attempts:
2 left
💡 Hint
Consider trade-offs between image size, build speed, and tool availability.