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.
More on Images, Layers & Storage Drivers
What is a Docker image made of?BeginnerWhat is a layer and when is one created?BeginnerWhat is a union filesystem / OverlayFS?IntermediateWhat is copy-on-write (CoW) in containers?IntermediateWhat storage drivers does Docker support and which is default?IntermediateWhat is the containerd image store and how does it differ from the classic graph driver store?Advanced