pivovarit pivovarit - 11 months ago 87
Git Question

Freeing unnecessary Docker image's space

I have a maven project that I am building and running inside Docker container. My maven build needs to have an access to my project's GIT repository for some commit info extraction so I need to temporarily include my repository inside an image.

The problem is that my repository weights more than 600MB and it makes my image unnecessarily huge. I cannot add my repo to an image, perform some action and then remove it later. Well, I can. But it will not save any space due to nature of Docker images. Any ideas on how to deal with this?

Answer Source

You could consider accessing the git repo through a host volume mounted in your docker container.

Or you could consider cloning only the part of the git repo you need (just one branch, only a few commits as a shallow clone). That would minimize the size of the git repo in the image.