increasingly developers are using Java in the context of container runtimes such as Docker, podman and kubernetes.
As containers are primarily resource managers which provide some level of resource control and isolation, such behavior(s) can impact the serviceability of a JVM executing in such a context.
It would be (highly) desirable to be able to determine if a JVM r/t is (or is not) executing within the context of such a container/resource controller.
Unfortunately there does not appear to be an existing platform API that can provide this information to the Java r/t, so some type of heuristic would need to be used, e.g:
- filesystem of type 'overlay' mounted on '/'
- introspection of pid 1 (init or systemd vs. some other arbitrary process)
- existence of env var or file: /run/.containerenv for podman