What’s the best way to pass JVM heap options like -Xms512m -Xmx1024m to the container — should I modify the Dockerfile or set them at runtime (e.g., in docker-compose)?
from what I remember spring-boot uses port 8080 by default. Is there a reason you change it to port 8082? It’s good practice to run applications with their default ports inside containers, and publish the host port of your choosing for the running container.
Your CMD uses the “exec form”, which does not allow using variables. You will want to use something like this:
CMD exec java $JAVA_OPTS -jar app.jar
Then you can use set the JAVA_OPTS environment variable in your compose file to set the options for the jvm.
Since I am not a Java developer, I wasn’t sure if it was for the same purpose, but a stack overflow comment indicates it is, although that was about oracle java
Then you don’t need to change the CMD instruction.
The ENV instruction in the Dockerfile just adds a default value. It could be a good idea to add to not have an undefined variable and to show that it can be set, but not strictly necessary.
Have you tried the other variable I mentioned? I’m curious if that works. official images usually don’t require changing the CMD or entrypoint for such a common parameter.