Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Java heap size (Xms/Xmx) inside Docker container?

As of raising this question, Docker looks to be new enough to not have answers to this question on the net. The only place I found is this article in which the author is saying it is hard, and that's it.

like image 808
Tung Nguyen Avatar asked Apr 28 '15 15:04

Tung Nguyen


People also ask

How do I change the memory limit on a docker container?

Set Maximum Memory Access To limit the maximum amount of memory usage for a container, add the --memory option to the docker run command. Alternatively, you can use the shortcut -m . Within the command, specify how much memory you want to dedicate to that specific container.

How do I change from XMS to XMX in Java?

The short answer is that you use these java command-line parameters to help control the RAM use of application: Use -Xmx to specify the maximum heap size. Use -Xms to specify the initial Java heap size. Use -Xss to set the Java thread stack size.


1 Answers

Note that in a docker-compose.yml file - you'll need to leave out the double-quotes:

  environment:   - JVM_OPTS=-Xmx12g -Xms12g -XX:MaxPermSize=1024m 

or

  environment:   - CATALINA_OPTS=-Xmx12g -Xms12g -XX:MaxPermSize=1024m 
like image 101
hawkeye Avatar answered Sep 20 '22 15:09

hawkeye