0
0
Dockerdevops~20 mins

Minimizing layers in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Layer Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why minimize layers in a Docker image?

What is the main benefit of minimizing the number of layers in a Docker image?

AIt reduces the final image size and improves build speed
BIt increases the number of containers that can run simultaneously
CIt allows running containers without root privileges
DIt automatically updates the base image to the latest version
Attempts:
2 left
💡 Hint

Think about how Docker stores image data and how layers affect storage.

💻 Command Output
intermediate
1:30remaining
Output of combined RUN commands

What will be the size difference between these two Dockerfiles after building?

Dockerfile A:

FROM alpine
RUN apk add curl
RUN apk add git

Dockerfile B:

FROM alpine
RUN apk add curl && apk add git
ADockerfile B will have a smaller image size because it creates fewer layers
BDockerfile B will fail to build due to syntax error
CBoth images will have the same size because the packages installed are identical
DDockerfile A will have a smaller image size because it separates commands
Attempts:
2 left
💡 Hint

Consider how Docker layers are created for each RUN command.

Configuration
advanced
2:00remaining
Correct Dockerfile to minimize layers and clean cache

Which Dockerfile snippet correctly installs packages and cleans cache in a single layer to minimize image size?

A
RUN apt-get update && apt-get install -y curl git
RUN rm -rf /var/lib/apt/lists/*
B
RUN apt-get update
RUN apt-get install -y curl git
RUN rm -rf /var/lib/apt/lists/*
CRUN apt-get update && apt-get install -y curl git && rm -rf /var/lib/apt/lists/*
D*/stsil/tpa/bil/rav/ fr- mr && tig lruc y- llatsni teg-tpa && etadpu teg-tpa NUR
Attempts:
2 left
💡 Hint

Think about how to combine commands to avoid extra layers and clean cache in the same layer.

Troubleshoot
advanced
2:00remaining
Why does this Docker image grow unexpectedly large?

A developer wrote this Dockerfile snippet:

RUN apt-get update
RUN apt-get install -y curl
RUN rm -rf /var/lib/apt/lists/*

Why does the final image size remain large despite cleaning the cache?

ABecause the base image is too large to reduce
BBecause each RUN creates a new layer, the cache files remain in previous layers
CBecause apt-get install does not actually install curl in this syntax
DBecause rm -rf command is incorrect and does not delete files
Attempts:
2 left
💡 Hint

Think about how Docker layers store filesystem changes.

🔀 Workflow
expert
2:30remaining
Optimal Dockerfile layering order for build cache efficiency

Given these Dockerfile commands, which order minimizes rebuild time when only application code changes?

1. COPY package.json /app/
2. RUN npm install
3. COPY . /app
ARUN npm install → COPY package.json /app/ → COPY . /app
BCOPY . /app → COPY package.json /app/ → RUN npm install
CCOPY . /app → RUN npm install → COPY package.json /app/
DCOPY package.json /app/ → RUN npm install → COPY . /app
Attempts:
2 left
💡 Hint

Consider which files change frequently and how Docker caches layers.