Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set heap size for wildfly inside Docker container?

I am trying to increase heap size for wildfly in docker container. This is easily done by updating wildfly/bin/standalone.conf in a regular wildfly setup.

Our base docker image for wildfly has a default heapsize of 512 MB which is required to be 1GB in one of the web apps. One way to go is by simple text replace in the Docker file using sed command -

RUN sed -i -- 's/JAVA_OPTS="-Xms64m -Xmx512m -XX:MaxPermSize=256m/JAVA_OPTS="-Xms2048m -Xmx6144m -XX:MaxPermSize=256m/g' /path/standalone.conf

I wanted to know if there's another (cleaner) way to solve this?

like image 201
Ankit Rustagi Avatar asked Dec 19 '16 11:12

Ankit Rustagi


People also ask

How do I increase my WildFly heap size?

Using an Environment Variable We can also set the default heap memory size by setting the JAVA_OPTS environment variable, which will override the value in the startup file. We can set the environment variable from a command prompt/ terminal.

How do I increase heap size in Kubernetes?

To manually change the heap size of Elasticsearch, set the ES_JAVA_OPTS environment variable in the podTemplate . Make sure you set the resource requests and limits at the same time so that the Pod gets enough resources allocated within the Kubernetes cluster.

How do I fix OOM issue in a Docker container?

By default, if an out-of-memory (OOM) error occurs, the kernel kills processes in a container. To change this behavior, use the --oom-kill-disable option. Only disable the OOM killer on containers where you have also set the -m/--memory option.


1 Answers

You can pass the value of the JAVA_OPTS environment variable in the command used to run the docker container:

docker run -it --env JAVA_OPTS="-server -Xms2048m -Xmx6144m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true" jboss/wildfly

Alternatively, you can extend the standard image by creating a Dockerfile containing:

FROM jboss/wildfly:latest

COPY standalone.conf $JBOSS_HOME/bin/

and placing your modified standalone.conf in the directory next to it.

Then you can build it:

docker build -t my/wildfly:latest .

and run it:

docker run my/wildfly
like image 197
Steve C Avatar answered Sep 29 '22 02:09

Steve C