What an image is
Deleting a file makes the image bigger
Why `RUN rm` does not reclaim space, what a whiteout actually is, and the difference one `&&` makes.
The delete that isn't
If a layer records what changed, what does it record when you delete something? It cannot remove the bytes: those are in a layer below, and layers below are immutable — other images may be sharing them.
So it records a marker. A whiteout is an entry that says: whatever the layers beneath me put at this path, hide it. The file disappears from the filesystem a container sees. The bytes stay exactly where they were, in a layer that is still in the image, still in the registry, and still readable by anyone who pulls it and unpacks that layer by hand.
A whiteout costs a tar header and no content — 512 bytes. So deleting a four-hundred-megabyte file adds 512 bytes to your image and removes nothing from it.
This is not a size problem with a security footnote. It is a security problem that happens to show up in the size column.
Predict first
You fetch a 40 MB archive in one RUN and delete it in the next. What happens to the image size?
Dockerfile
- 1
- 2
- 3
- 4
Layers
Nothing has been built yet. Press Build and the layers, the digest and the cache ledger appear — not before.