Recently I created a docker container from a centos base image which ran a jboss. Originally I had installed the jdk (and committed) which made the container bulky (about 850M). Later, I uninstalled jdk and installed jre. From inside the container a
du -xsh /
shows only 440M. But after committing the changes to the image it still shows 711M. Should the image size not match (or be close to) the container's du? Or while committing, does docker keep adding to the old ones (like an SCM)?
Thanks
Answering my own question. It seems that docker keeps adding layer to the base image whenever one commits to the image. However little you make your container committing it to the base is going only to add a new layer over the existing image which is always going to inflate the image. The problem with this approach is when you make modifications and commit to the base image, you end up taking unwanted layers to the production. I can see no official way to merge the layers. But there seems to be some workarounds in this link. However, I just recreated everything from the base and committed only once which made the image size very close to the container size.
I think you will find this issue easily resolvable if you are using Dockerfiles to build your images, rather than the commit method. If you are using Dockerfiles, you can simply remove the RUN command that added the JDK, and rebuild. This will get rid of the previous layers.