You can limit amount of memory used by JVM in containerized environment with:
When using container technology, applications are typically run on their own and do not need to compete for memory. The JVM now has automatic container detection support, which makes it possible for the JVM to determine the amount of memory and number of processors that are available to a Java process running in docker containers that imposes limits. It uses this information to allocate system resources. This support is only available on Linux x64 platforms. If supported, the default for this flag is true, and container support is enabled by default. It can be disabled with -XX:-UseContainerSupport. If this option is disabled, then JVM will try to acquire resources from the host machine, bypassing container limits.
Unified Logging is available to help to diagnose issues related to this support.
Use -Xlog:os+container=trace for maximum logging of container information.
Default value is true
TODO link Xloggc, Xlog:gc
If you have additional comments, interesting experiences or even point of disagreement with this JVM argument description, please leave a comment. Your insights will help the entire 10+ million java developer community to develop one standard source of documentation for all the JVM arguments.