Interview Prep/Docker/Images, Layers & Storage Drivers

Why does deleting a file in a later `RUN` not shrink the image?

IntermediateConceptImages, Layers & Storage Drivers
Answer

Layers are additive. A deletion in a later layer adds a whiteout marker; the original bytes still exist in the earlier layer and are still downloaded. Clean up in the same RUN step:

RUN apt-get update && apt-get install -y --no-install-recommends curl \
    && rm -rf /var/lib/apt/lists/*

Or use multi-stage builds so the junk never reaches the final stage.

All Docker questions Roadmap: Docker & containers

More on Images, Layers & Storage Drivers