0
0
Dockerdevops~20 mins

Reducing image size strategies in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Docker Image Size Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why use multi-stage builds in Docker?

What is the main reason to use multi-stage builds when creating Docker images?

ATo run multiple containers from one Dockerfile simultaneously
BTo separate build dependencies from runtime, reducing final image size
CTo speed up the container startup time by caching layers
DTo allow Docker images to run on different operating systems automatically
Attempts:
2 left
💡 Hint

Think about how build tools and runtime requirements differ.

💻 Command Output
intermediate
2:00remaining
Output of Docker image size after cleaning cache

What will be the effect on the Docker image size after running RUN apt-get clean && rm -rf /var/lib/apt/lists/* in a Dockerfile?

Docker
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y curl \
    && apt-get clean && rm -rf /var/lib/apt/lists/*
AThe image size increases due to added cleanup commands
BNo change in image size because cache files are stored outside the image
CThe image size decreases because package cache files are removed
DBuild will fail because rm command is invalid in Dockerfile
Attempts:
2 left
💡 Hint

Consider where package cache files are stored and if they remain in the image layers.

Configuration
advanced
2:00remaining
Choosing base images for smaller Docker images

Which base image choice will generally produce the smallest Docker image for a Node.js app?

Anode:alpine
Bnode:latest
Cubuntu:22.04
Ddebian:stable-slim
Attempts:
2 left
💡 Hint

Think about minimal Linux distributions optimized for small size.

Troubleshoot
advanced
2:00remaining
Why does the Docker image remain large despite cleanup commands?

You added cleanup commands to your Dockerfile to remove temporary files after installing packages, but the final image size is still large. What is the most likely reason?

AThe Dockerfile must use COPY instead of RUN for cleanup to work
BDocker caches all files permanently regardless of cleanup commands
CCleanup commands only work on Alpine images, not Ubuntu-based ones
DEach RUN command creates a new layer; cleanup must be in the same RUN as install
Attempts:
2 left
💡 Hint

Think about how Docker layers work and when files get saved.

🔀 Workflow
expert
3:00remaining
Optimizing Dockerfile for smallest image with build artifacts

You have a Dockerfile that compiles a Go application and then copies the binary to a minimal image. Which multi-stage Dockerfile snippet correctly produces the smallest final image?

Docker
FROM golang:1.20 AS builder
WORKDIR /app
COPY . .
RUN go build -o myapp

FROM scratch
COPY --from=builder /app/myapp /myapp
CMD ["/myapp"]
AUse <code>FROM scratch</code> as final stage and copy only the binary from builder
BUse <code>FROM golang:1.20</code> as final stage and copy all files from builder
CUse <code>FROM ubuntu</code> as final stage and copy the binary and source files
DUse <code>FROM alpine</code> as final stage and copy the entire /app directory
Attempts:
2 left
💡 Hint

Consider the smallest base image possible and copying only what is needed.