Skip to content

Small images and vulnerability scanning

Select an icon to see what it is.

Step 2 of 6

Deleting in a later layer does not shrink the image

Each RUN adds a layer, and a layer is never edited later. If one RUN installs packages and the next RUN deletes the cache, the files still sit in the first layer and are only hidden. Doing both in a single RUN means the cache never reaches a layer.

docker history (shape)

A: RUN apt-get update && apt-get install -y curl big layer, includes the package lists
RUN rm -rf /var/lib/apt/lists/* tiny layer, hides files but frees nothing
B: RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* one smaller layer