13

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?

2
  • 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, 2015 at 23:06
  • See this SO question for a howto. Also, this Google search has a number of relevant articles. May 2, 2015 at 16:12

3 Answers 3

10

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.

5

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.

0

Every line in the dockerfile creates a new layer. So even if you try to remove something it creates new layer from the layer from its previous step. Remember layers are only additive and docker has no idea what rm is actually doing, it only stacks them up sp 14gb + remove file == 14 gb + metadata of the new command. In order to fix this try to make sure you are adding and removing the tmp folder on the line of the docker file as @Wernight suggested.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .