0
0
Dockerdevops~20 mins

Reducing final image size by 80 percent 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 aiming to reduce Docker image size by 80%?

ATo automatically compress the image after building
BTo run multiple containers simultaneously for faster builds
CTo cache all layers and speed up network downloads
DTo separate build dependencies from runtime dependencies, keeping only necessary files in the final image
Attempts:
2 left
💡 Hint

Think about how build tools and runtime environments differ in what files they need.

💻 Command Output
intermediate
2:00remaining
Output of docker image size after optimization

Given a Dockerfile that uses alpine as the base image and copies only the compiled binary, what is the expected approximate size of the final image?

AAbout 500 MB
BAbout 5 MB
CAbout 50 MB
DAbout 1 GB
Attempts:
2 left
💡 Hint

Alpine Linux base images are known for being very small.

Configuration
advanced
3:00remaining
Identify the correct Dockerfile snippet to reduce image size

Which Dockerfile snippet correctly uses multi-stage build to reduce final image size by copying only the compiled binary?

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 ["/usr/local/bin/myapp"]
A
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 ["/usr/local/bin/myapp"]
B
FROM alpine:latest
COPY myapp /usr/local/bin/myapp
ENTRYPOINT ["/usr/local/bin/myapp"]
C
FROM golang:1.20
WORKDIR /app
COPY . .
RUN go build -o myapp
ENTRYPOINT ["./myapp"]
D
FROM alpine:latest
RUN apk add go
WORKDIR /app
COPY . .
RUN go build -o myapp
ENTRYPOINT ["/usr/local/bin/myapp"]
Attempts:
2 left
💡 Hint

Look for the snippet that builds in one stage and copies only the binary to a smaller image.

Troubleshoot
advanced
2:30remaining
Why does the final image remain large despite multi-stage build?

You used a multi-stage Dockerfile to reduce image size, but the final image is still over 500 MB. What is the most likely cause?

AYou used a multi-stage build with separate stages
BYou used Alpine as the base image in the final stage
CYou copied the entire build context instead of only the binary in the final stage
DYou did not run <code>docker system prune</code> after building
Attempts:
2 left
💡 Hint

Check what files are copied into the final image.

Best Practice
expert
3:00remaining
Best practice to reduce Docker image size by 80% in CI/CD pipelines

In a CI/CD pipeline, what is the best practice to ensure Docker images are consistently reduced by 80% in size?

AUse multi-stage builds, clean up unnecessary files, and use minimal base images like Alpine or scratch
BBuild images on developer machines and push them to the registry
CUse large base images to avoid compatibility issues
DAvoid using multi-stage builds to speed up build time
Attempts:
2 left
💡 Hint

Think about combining multiple strategies for image size reduction.