Hi I have a docker image which runs a spring boot service to which I need to pass --add-opens argument. Below is content of my docker file
FROM amazoncorretto:21.0.4
ENV JAVA_TOOL_OPTIONS="-Xms2g -Xmx8g -XX:MaxMetaspaceSize=512M -XX:+UseG1GC --add-opens java.base/java.lang=ALL-UNNAMED"
# Add the JAR file to the container
ADD target/evaluation-service.jar evaluation-service.jar
# Define the entry point
ENTRYPOINT ["java", "-jar", "evaluation-service.jar"]
For running this image I use below command
docker run --platform linux/arm64 -d --expose 8302 -p 8302:8302 --memory=8g --name evaluation 285bc34ead55 --server.port=8302
But when I run this command I get below error
Picked up JAVA_TOOL_OPTIONS: -Xms2g -Xmx8g -XX:MaxMetaspaceSize=512M -XX:+UseG1GC --add-opens java.base/java.lang=ALL-UNNAMED
Unrecognized option: --add-opens
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit
If i remove "--add-opens java.base/java.lang=ALL-UNNAMED" from jvm args then image starts up without any issue. What I am doing wrong here?
If used in JAVA_TOOL_OPTIONS, I think you have to put equal sign =
after --add-opens
so you will have:
--add-opens=java.base/java.lang=ALL-UNNAMED
From my experience, without equal sign it works when JDK_JAVA_OPTIONS is used.