I have container running GlassFish. When I tried commit a image , it became 14GB. Later, I deleted /tmp/ in the container which was 10GB and tried to commit a image, but still the image is 14GB. It seems that deleting files from the container is not reflected in the image size. How do I fix this issue?

  • 1
    No one can really make any recommendations without knowing a bit more about your setup. What is the Dockerfile? What is the file tree that gets added to the Docker build context? The official glassfish Docker image is about 1 GB. While pretty damn big for a Docker image, it is still much smaller than what you appear to be building. – Andy Shinn Mar 17 '15 at 23:06
  • See this SO question for a howto. Also, this Google search has a number of relevant articles. – Misha Brukman May 2 '15 at 16:12

The problem that you might be facing is that removing files in a commit does not change the fact that the file was there in a previous image, so that previous image is still 14G.

Have a look at the "Layers" part in this article: http://woudenberg.io/reducing-docker-image-size/

To solve that issue you need to remove the things under /tmp/ within the original commit that generated them, so the image created as a result of that commit does not include them. That is easy when use dockerfiles but not sure if possible when creating images with commits.

Another thing you may be able to do is squash layers by exporting/importing the image.


Extending on @Juan Antonio's answer, having a Dockerfile doing this will not save space:

RUN apt-get install -y foo bar
RUN apt-get purge --auto-remove -y foo bar

What you need to do instead is:

RUN apt-get install -y foo bar && \
    && ... \
    && apt-get purge --auto-remove -y foo bar

On the down side, this means less caching as if anything changes in that large command line, Docker will have to re-run the entire set of commands.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.