Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker creates huge image sizes

Tags:

java

docker

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
like image 798
gammay Avatar asked Dec 22 '14 14:12

gammay


3 Answers

A few points:

  • This Dockerfile will build a very minimal Oracle JDK image. Also read the accompanying blog post.
  • You probably don't need the JDK for running your containers and can get away with a JRE based container. You can always use a separate compiler container for creating the jar to go into the application container.
  • If you can, consider using the official Java images built on OpenJDK, which are reasonably small.
  • Ideally you should put separate processes such as MySQL into separate containers.
like image 98
Adrian Mouat Avatar answered Oct 02 '22 11:10

Adrian Mouat


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.

like image 39
johnmcdnl Avatar answered Oct 02 '22 13:10

johnmcdnl


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.

like image 43
johncosta Avatar answered Oct 02 '22 13:10

johncosta