I'd like to incrementally create a docker image without keeping the intermediate layers.
I understood that docker keep the intermediate layers in order to be able to roll back to a previous version of the image, but I'm not interested in this feature.
The docker-squash project seems to provide a solution, but it has been archived and not maintained for 5 years.
Here is a simple example explaining what I mean
I have an image of 72.7MB
image1 latest 9873176a8ff5 4 weeks ago 72.7MB
I add a 10MB file to a container and commit it to image2
docker run -it image1 /bin/bash
truncate -s 10MB 10MB_FILE
docker cp 10MB_FILE container_id:/
docker commit -m "add 10MB" container_id image2
image2
weigh 10MB more
image2 latest b7d1ea4043fb 58 seconds ago 82.7MB
I remove the 10MB file from a container and commit it to image3
docker run -it image2 /bin/bash
rm 10MB_FILE
exit
docker commit -m "remove fime" container_id image3
image3
weigh the same
image3 latest 11ff12ee0626 4 seconds ago 82.7MB
I would like to have an image3
weighing 72.7MB.
I don't want to simply revert a commit because there might be some other commit that I want to keep in between the commit where I add the file and delete the file.
I know that I can change the Dockerfile and rebuild from scratch (as answered here), but some installs take a lot of time to do. This is why I want to incrementally create the docker image with docker commit
.