Java memory and Docker
From JDK 8u131+ and JDK 9, there’s an experimental VM option that allows the JVM ergonomics to read the memory values from CGgroups. To enable it on, you must explicit set the parameters
-XX:+UseCGroupMemoryLimitForHeap on the JVM.
-Xmx flag in JVM before 8u131 still resulted in Java trying to allocate more memory than allowed by docker because it detected all memory available instead of the docker limits. Docker in turn killed the container.
No combination of flags allowed us to set limits. Migrating to the newer jetty image with the updated JRE 8 finally addressed this issue.