I have build a docker image by making incremental commits. This has led to the creation of a lot of layers in my docker image and subsequently the size of the image has gone very large.
Is there a way to remove the layers and as a result reduce the size of the image ?
Any help would be appreciated.
You could try to export the image and then import it again. By doing it this way all the layers will be lost and your image size will be lower.
sudo docker export red_panda > exampleimage.tar
cat exampleimage.tar | sudo docker import - exampleimagelocal:new
Note that this only works with containers, so you will need to launch one from the image and then do the trick.
Hope it helps.
You can squash layers with next trick
FROM oracle AS needs-squashing
ENV NEEDED_VAR some_value
COPY ./giant.zip ./somewhere/giant.zip
RUN echo "install giant in zip"
RUN rm ./somewhere/giant.zip
FROM scratch
COPY --from=needs-squashing / /
ENV NEEDED_VAR some_value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With