It stays about the same, because the files still exist in the earlier layers
The image stays about the same size, because the files still exist in the earlier layers. Image layers only add. The new layer only records that the files are deleted. The earlier layer still contains the files, and Docker still ships it. So "It shrinks by the size of the deleted files" is wrong.
To really save space:
• delete the files in the same RUN instruction that created them, or
• use a multi-stage build and copy only the files you need.
Read more