Docker Images & Layers — Concept Check
Questions on Docker Images & Layers. Docker images are built from stacked read-only layers stored in a Union File System. Understanding layers is the key to writing efficient Dockerfiles and keeping image sizes small.
Questions in this quiz
8 questions on Docker Images & Layers — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.You have a Dockerfile with the following instructions: FROM node:20-alpine, WORKDIR /app, COPY . ., RUN npm ci. After making frequent source code changes, what issue might you encounter?
- AIncreased build time due to cache invalidation
- BImproved build time due to efficient layer usage
- CDecreased build time due to reduced layer count
- DDecreased image size due to layer optimization
2.A developer wants to optimize their Dockerfile by reducing image size. Which strategy should they use?
- AAdd cleanup commands in separate RUN steps
- BUse Ubuntu base images for more features
- CCombine RUN commands to merge layers
- DUse COPY instead of ADD for all files
3.You notice that two Docker images share a base layer. What is the storage implication of this?
- AThe base layer is stored once and shared
- BEach image stores its own copy of the base layer
- CThe base layer is stored twice on disk
- DThe base layer is not stored on disk
4.A Dockerfile includes: FROM node:20-alpine, WORKDIR /app, COPY package*.json ./, RUN npm ci, COPY . .. What is the benefit of this order?
- AIt reduces the number of layers
- BIt ensures npm ci runs on every build
- CIt avoids copying unnecessary files
- DIt caches npm ci unless package.json changes
5.You run docker history on an image and see a large size for a RUN layer. What might be the cause?
- AUsing a large base image
- BSeparate RUN steps for each command
- CMultiple commands combined in one RUN step
- DUsing COPY instead of ADD
6.A developer claims their Docker container starts slowly. What might be a cause unrelated to image layers?
- AImage layers are not on disk
- BBase image size is too small
- CExcessive layers increase startup time
- DThe writable layer is too large
7.Which of the following Dockerfile instructions does NOT create a new layer?
- ARUN
- BCOPY
- CWORKDIR
- DFROM
8.What happens when a layer in a Docker image changes?
- AAll layers are rebuilt from scratch
- BOnly the changed layer is rebuilt
- CThe changed layer and all subsequent layers are rebuilt
- DOnly subsequent layers are rebuilt