JDK-8254091 : Need a mechanism (and API) to reliably determine if a JVM is executing in a container context
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: svc
  • Affected Version: 16
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • Submitted: 2020-10-06
  • Updated: 2024-06-20
  • Resolved: 2024-06-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Relates :  
Description
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

Comments
This is the same bug as JDK-8261242 where I've done some experiments (and failed).
06-05-2022

c.f: https://github.com/opencontainers/runtime-spec/issues/1070
09-10-2020