How to configure Java heap #37
Comments
@step76 Right now, the only way to do this is to replicate the default command with your additional flags. Here's what it looks like in a Dockerfile: FROM jetty:9.3
CMD ["java","-Djava.io.tmpdir=/tmp/jetty","-Xmx1g","-jar","/usr/local/jetty/start.jar"] Here's what it looks like on the command line: $ docker run -d -p 80:8080 -p 443:8443 jetty java -Djava.io.tmpdir=/tmp/jetty -Xmx1g /usr/local/share/jetty/start.jar |
@gregw This seems to be a drawback of moving away from |
We could look at that, but it would be very difficult to come up with a one size fits all script. Isn't the solution here to modify the docker-entrypoint.sh script to inject $JAVA_OPTIONS into the default command line? Perhaps we change the default CMD to just be the arguments to java, as the entry point already handles that and injects a java command. That way if somebody explicitly specified a java command they could set whatever options they like... if they went with the default then they would be able to use JAVA_OPTIONS to control the the JVM. I'd much rather just have a single script rather than a script that invokes another script and then jetty. |
@gregw If we put that into the entrypoint, then the I'd rather not have the default I suppose that modifying the entrypoint to know about Incidentally, I noticed while investigating this that the argument order in the entrypoint is weird. The |
@md5 quick explanation of the ordering and then I'll consider other points in another comment. The start.jar mechanism can look at the modules and determine that jvm args are needed (Eg if ALPN was enabled), so in that case start.jar will fork another JVM instance. Putting the -D after the -jar means that the JVM arg is for the JVM that will run jetty and not for the instance that will run start.jar. So that's how it works. However, it should be safe to put it before the -jar as such values should be copied over to the target JVM if one is needed. Putting it after the -jar means that a second JVM is always needed. So let's open another issue to consider if that is the ordering we want: #38 |
So how about making the CMD:
Note the $, so the entry point script can look for unexpanded $JAVA_OPTIONS and do the expansion. This would allows users to over-ride the command and decide to either use that expansion or instead directly specify all their args |
@gregw I'm not too keen on detecting the unexpanded @tianon Do you have any thoughts on this? To summarize:
Other Java daemons like Elasticsearch have their own shell script that knows to look for |
@tianon Also, as you may remember, this image originally called |
@md5 Currently we have CMD and entry point:
Which has the benefit of making the default command line visible in the docker file. However, let's say the distribution had a suitable
and we'd lose visibility of the default command line anyway. So can we not just have an empty default CMD and move all the default command line into docker-entrypoint.sh:
Users could then: set just |
@gregw I think losing visibility of what's inside the Since that's not currently the case and it doesn't seem to be on your roadmap, then I think doing something in the entrypoint makes sense. I'm not sure whether or not having a default |
@md5 as @tianon is currently silent, I've had a look at some of the docker images he works on:
But interesting the docker-entrypoint.sh script inspects and modifies that CMD. If it is left as He's not committed to many other directly relevant projects, but looking further afield I can see other examples of entry points that modify the CMD from the docker file: So if we had an entry point that checked if $1 was java and if so it added $JAVA_OPTIONS, then we would not be an island. I think I'll prepare a PR for this. |
Sounds good. It make take me a few days to review since we're coming into a
holiday weekend here in the US
|
This PR includes the fix for [37](appropriate/docker-jetty#37). The `docker-entrypoint.sh` script has been updated to include the `$JAVA_OPTIONS` environment variable in the command line arguments if the command is java.
@md5 I created the PR. However I could not find a script |
Oh man, my inbox is such a train wreck; sorry I missed this entire conversation! Glad it ended up in a solid place in spite of me! 👍 |
@md5 Argh! I missed the alpine subdir! Plus my manually updated stackbrew listed a newer tag for the alpine version! Standby.... |
Updated the alpine image with same changes previously made for appropriate#37 removed the unused ENV variables JETTY_RUN and JETTY_STATE
@md5 Here is another PR fixing alpine and also removing the now unused ENV variables |
Updated the alpine image with same changes previously made for appropriate#37 removed the unused ENV variables JETTY_RUN and JETTY_STATE
Updated the alpine image with same changes previously made for appropriate#37 removed the unused ENV variables JETTY_RUN and JETTY_STATE
This PR completes the fix for [37](appropriate/docker-jetty#37): - fix also applied to alpine image - removes unused ENV vars
Reopening as we need to update documentation. |
Hi, It's not that easy to follow the thread, at the end what would be the implemented solution? |
@lfoppiano You would pass $ docker run -d -p 80:8080 -p 443:8443 -e JAVA_OPTIONS='-Xmx1g' jetty If you have a derived image that is @gregw Would you still be willing to create a PR for the |
@md5 thanks. To check that the parameters are correctly set, I need to connect to the container
and check the environment variable:
|
There's not really a straightforward way to do that, but here are some options:
The third option looks like it's a bit problematic however... I can't actually get |
I opened a PR for the docs here: docker-library/docs#709 |
With the latest Here's an example command that gives the container 600 megabytes and give the JVM half of that memory: $ docker run -d -p 80:8080 -p 443:8443 --memory 600m \
-e JAVA_OPTIONS='-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -X:MaxRAMFraction=2' I'm going to close this issue since the the way to set the heap size has been documented. |
Is there a way to configure Java heap, or how to pass custom flags to the java VM?
The text was updated successfully, but these errors were encountered: