For hotspot one can disable container detection with a simple switch:
$ java -XX:-UseContainerSupport -Xlog:os+container=trace -version
[0.000s][trace][os,container] OSContainer::init: Initializing Container Support
[0.000s][trace][os,container] Container Support not enabled
openjdk version "15-internal" 2020-09-15
OpenJDK Runtime Environment (build 15-internal+0-adhoc.sgehwolf.openjdk-head-2)
OpenJDK 64-Bit Server VM (build 15-internal+0-adhoc.sgehwolf.openjdk-head-2, mixed mode, sharing)
The same cannot be achieved with the Java code,
jdk.internal.platform.Metrics.java and friends in the JDK. At the time
Metrics were added the only consumer of them was the Java Launcher via
-XshowSettings:system. This has changed with JDK-8226575:
OperatingSystemMXBean should be made container aware.
It is known that in certain cases the container detection code will
detect for a system to be supposedly in a container where it actually
isn't:
https://bugs.openjdk.java.net/browse/JDK-8227006?focusedCommentId=14275604&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14275604
For hotspot there is a flag, to turn auto-detection off for exactly the
case when heuristics are wrong: -XX:-UseContainerSupport. However, this
flag has no effect on the Java metrics code. There is a risk that on
some systems the auto-detection will be wrong and might cause
regressions.
I propose to make the Java metrics code adhere to -XX:+/-
UseContainerSupport flag.