I have copied TestFolder.zip to destinatination and space is allocated but when I have deleted “rm -rf TestFolder.zip” the space is not reclaimed. As a result, the image size is getting larger due to copy.
Use case: Copied an rpm and after installation of the rpm package while deleting the original rpm the space is not reclaimed.
Each COPY, ADD or RUN instruction will create a new layer. Files written in a layer, but deleted in a later layer, will only be marked as deleted. They will still physically exist in the layer they were written. A container created from that image will not see any files that are marked as deleted.
You need to make sure a file is created and deleted within the same layer. That’s why people usually download files from a http source, uncompress it and delete it in the same RUN instruction.
If you could switch from zip compress to tar, you could use the ADD instruction to extract the archive while adding it’s content to the image:
Just to be clear: it does not work with zip files.
My expectation is the size for layer Layer-2: will be decreased in Case-1, but actually it’s not happening.
Getting same image size for Case-1 and Case-2
My expectation was the size ocupied for the operation tar -C /DT/rel/IDAP/ -xvf /DT/temp/TestFolder.tar.gz was decreased. Is my expectation wrong?
Could you please guide me.
Note: I am using Azure RHEL8 system.