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?
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With