Top Description Constructors Methods
org.apache.commons.lang3

public Class RuntimeEnvironment

extends Object
Class Inheritance
Imports
java.io.IOException, java.nio.charset.Charset, java.nio.file.Files, .Paths, java.util.Arrays

Helps query the runtime environment.
Since
3.15.0

Constructor Summary

AccessConstructor and Description
public
RuntimeEnvironment()
Deprecated Will be removed in 4.0.0.

Constructs a new instance.

Method Summary

Modifier and TypeMethod and Description
private static boolean
fileExists(final String path)

public static Boolean

Returns:

whether we are running in a container like Docker or Podman. Never null.
inContainer
()

Tests whether we are running in a container like Docker or Podman.

pack-priv static boolean

Returns:

Whether we are running in a container like Docker or Podman.
inContainer
(final String dirPrefix)

Tests whether we are running in a container like Docker or Podman.

private static String

Returns:

value The env var value or null.
readFile
(final String
The path to a /proc/N/environ file.
envVarFile
,
final String
The env var key to find.
key
)

Tests whether the /proc/N/environ file at the given path string contains a specific line prefix.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

RuntimeEnvironmentback to summary
public RuntimeEnvironment()

Deprecated

Will be removed in 4.0.0.

Constructs a new instance.

Annotations
@Deprecated

Method Detail

fileExistsback to summary
private static boolean fileExists(final String path)
inContainerback to summary
public static Boolean inContainer()

Tests whether we are running in a container like Docker or Podman.

The following may change if we find better detection logic.

We roughly follow the logic in SystemD:

https://github.com/systemd/systemd/blob/0747e3b60eb4496ee122066c844210ce818d76d9/src/basic/virt.c#L692

We check the `container` environment variable of process 1:

  1. If the variable is empty, we return false. This includes the case, where the container developer wants to hide the fact that the application runs in a container.
  2. If the variable is not empty, we return true.
  3. If the variable is absent, we continue.
  4. We check files in the container. According to SystemD:/
    1. /.dockerenv is used by Docker.
    2. /run/.containerenv is used by PodMan.
Returns:Boolean

whether we are running in a container like Docker or Podman. Never null.

See Also
SystemD virt.c
inContainerback to summary
pack-priv static boolean inContainer(final String dirPrefix)

Tests whether we are running in a container like Docker or Podman.

The following may change if we find better detection logic.

We roughly follow the logic in SystemD:

https://github.com/systemd/systemd/blob/0747e3b60eb4496ee122066c844210ce818d76d9/src/basic/virt.c#L692

We check the `container` environment variable of process 1:

  1. If the variable is empty, we return false. This includes the case, where the container developer wants to hide the fact that the application runs in a container.
  2. If the variable is not empty, we return true.
  3. If the variable is absent, we continue.
  4. We check files in the container. According to SystemD:/
    1. /.dockerenv is used by Docker.
    2. /run/.containerenv is used by PodMan.
Returns:boolean

Whether we are running in a container like Docker or Podman.

See Also
SystemD virt.c
readFileback to summary
private static String readFile(final String envVarFile, final String key)

Tests whether the /proc/N/environ file at the given path string contains a specific line prefix.

Parameters
envVarFile:String

The path to a /proc/N/environ file.

key:String

The env var key to find.

Returns:String

value The env var value or null.