0
0
Dockerdevops~20 mins

Image size and minimal base images in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Image Size Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why choose minimal base images in Docker?

Which of the following is the main advantage of using minimal base images like alpine in Docker containers?

AThey include all development tools by default for easier debugging.
BThey automatically update to the latest OS version on container start.
CThey guarantee compatibility with all Linux distributions.
DThey reduce the final image size, improving download and startup speed.
Attempts:
2 left
💡 Hint

Think about what affects container download and deployment speed.

💻 Command Output
intermediate
1:30remaining
Output of Docker image size command

What is the output of the following command if you have a Docker image named myapp built from alpine base?

docker images myapp --format "{{.Repository}}: {{.Size}}"
Amyapp: 500MB
Bmyapp: 50MB
Cmyapp: 5MB
Dmyapp: 1GB
Attempts:
2 left
💡 Hint

Alpine base images are known for being very small, around 5MB.

Configuration
advanced
2:00remaining
Reducing Docker image size with multi-stage builds

Which Dockerfile snippet correctly uses multi-stage builds to reduce the final image size by excluding build tools?

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

FROM alpine:latest
COPY --from=builder /app/myapp /usr/local/bin/myapp
ENTRYPOINT ["myapp"]
AThe snippet uses multi-stage build to copy only the binary, reducing image size.
BThe snippet copies the entire builder image, increasing image size.
CThe snippet installs build tools in the final image, increasing size.
DThe snippet uses the same base image for both stages, no size reduction.
Attempts:
2 left
💡 Hint

Look for copying only the necessary files from the builder stage.

Troubleshoot
advanced
1:30remaining
Troubleshooting large Docker image size

You notice your Docker image size is unexpectedly large. Which of the following is the most likely cause?

AUsing multi-stage builds to separate build and runtime stages.
BIncluding unnecessary packages and files in the image layers.
CUsing a minimal base image like Alpine.
DRemoving cache after package installation.
Attempts:
2 left
💡 Hint

Think about what adds extra weight to an image.

Best Practice
expert
2:30remaining
Best practice for minimal Docker images with Python apps

Which Dockerfile approach best minimizes image size for a Python application?

FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "app.py"]
AUse <code>python:3.12-slim</code> with <code>pip install --no-cache-dir</code> to avoid cache files.
BUse <code>python:3.12</code> full image for maximum compatibility.
CInstall packages with cache to speed up builds.
DUse <code>python:3.12-alpine</code> without adjusting pip install options.
Attempts:
2 left
💡 Hint

Consider both base image size and package installation options.