问题
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?
回答1:
When using docker-compose
set environment variable as follows!
environment:
- JAVA_OPTS=-server -Xms512m -Xmx2048m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -XX:+UseAdaptiveSizePolicy -XX:MaxMetaspaceSize=1024m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true-Djava.net.preferIPv4Stack=true
do not use "
(quotes)!
回答2:
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
回答3:
I suggest you to use JAVA_TOOL_OPTIONS rather than JAVA_OPTS .Because JVM directly understand JAVA_TOOL_OPTIONS.
来源:https://stackoverflow.com/questions/41221742/how-to-set-heap-size-for-wildfly-inside-docker-container