Reputation: 6215
I pulled base ubuntu:latest image (size 192.7 MB) and installed only Oracle java7 (JDK) to it (size of tar.gz ~53MB) and committed the resulting image. The image size is 903MB.
Why has the image size increased by such huge margin? We still need to add other components (tom cat, vertx, mysql, etc.). The image size will become unmanageable.
Any tips on how to reduce the image size?
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
gammay/baseimage v0.1a 80324b762c5e 21 minutes ago 903.6 MB
ubuntu latest 9bd07e480c5b 2 weeks ago 192.7 MB
Upvotes: 11
Views: 4743
Reputation: 32166
You can optimize your image
http://www.centurylinklabs.com/optimizing-docker-images/
and your image can lose some weight with
https://github.com/jwilder/docker-squash
You can also create a small image with the tool in this article
http://blog.xebia.com/2015/06/30/how-to-create-the-smallest-possible-docker-container-of-any-image/ and the tool strip-docker-image available at
https://github.com/mvanholsteijn/strip-docker-image
Upvotes: 0
Reputation: 46480
A few points:
Upvotes: 15
Reputation: 3807
Any tips on how to reduce the image size?
You could try to do the following:
Are you building java from source? If so, are there options you can disable that aren't needed for your application? Are there any dev packages that are not needed at runtime? You might be able to get rid of those too.
Run mysql in its own container and connect your web application container to your mysql container, possibly through container links. There's a few reasons for doing it this way, one of which is for easier scaling of your application components.
Build your tomcat instance in such a way that you have a tomcat container and your application jar. You can then mount your application using a data volume to the tomcat container. Your application image should be relatively small compared to the tomcat/java container. Updating your application becomes a little easier since you won't need to rebuild tomcat/java images at the same time (unless there's additional features you need to bake into tomcat.
Upvotes: 1
Reputation: 11
Java7 probably has a large number of dependencies that need to be installed for it to run that aren't installed on your base Ubuntu image. All of these are also installed when you install java which probably explains the large image size.
Upvotes: 1