DEV Community

Jashua
Jashua

Posted on

Why do Java containers (docker) take so much memory?

I might be doing something wrong, I was just testing how to "dockerize" a spring boot FatJar

First I tried a simple Eureka server, docker showed around 350 mb memory usage.

I went ahead to dockerize a simple hello world, it has nothing else on it, yet it was taking around 150 mb memory.

Is this normal? why does it need that much? I don't get it

Top comments (6)

Collapse
 
wayofthepie profile image
wayofthepie

I wrote a post a while back that goes into a bit of depth around jvm memory usage, see

For the hello world app you can probably set -Xms and -Xmx to 5m, so java -Xms5m -Xmx5m Program. Xms sets the initial heap size, Xmx sets the max. There are lots of memory areas besides the heap though, as mentioned in the above post, so this will still use maybe 50MiB of memory or more.

As for figuring out what you should set for a given program, that generally takes a bit of profiling while the app is running with tools like jmap, jconsole, visualvm etc... Or just plain trial and error in some cases.

Collapse
 
jouo profile image
Jashua

Thank you very much, very informative post! :)

I'm going to learn one of those tools, right now I feel clueless about anything related to memory

Collapse
 
wayofthepie profile image
wayofthepie

There is definitely a lot to learn, I'm still learning new things most days! Good luck 👍

I'm going to do a more practical post around tuning the jvm soon.

Collapse
 
theodesp profile image
Theofanis Despoudis

Yeap that's Java heap space. you can control it via JVM args. See: link

Collapse
 
jouo profile image
Jashua

Oh that's interesting!

But how do people know how much memory should an application need?

for example that simple web app that only returns "Hello World", how do I know how much memory is enough?

Collapse
 
theodesp profile image
Theofanis Despoudis • Edited

I think you might need to check minimum hardware requirements depending on the JVM version. For example here is for Java 7 or 8

java.com/en/download/help/sysreq.xml

You can also consult on this guide:

docs.oracle.com/cd/E15523_01/web.1...

Because the app is a hello world, then I would assume that you will need the minimum (say a safe 8mb)