Package org.eclipse.hono.util
Class KubernetesContainerUtil
java.lang.Object
org.eclipse.hono.util.KubernetesContainerUtil
Locate the current docker container.
This class has been copied from org.apache.logging.log4j.kubernetes.ContainerUtil from the log4j-kubernetes module of the Apache Log4j 2 project (commit a50abb9). Adaptations have been done concerning the used logger and the Hono code style. Also a fix regarding cri-containerd container ids has been applied.
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
Returns the container id when running in a Docker container.
-
Method Details
-
getContainerId
Returns the container id when running in a Docker container. This inspects /proc/self/cgroup looking for a Kubernetes Control Group. Once it finds one it attempts to isolate just the docker container id. There doesn't appear to be a standard way to do this, but it seems to be the only way to determine what the current container is in a multi-container pod. It would have been much nicer if Kubernetes would just put the container id in a standard environment variable.See Stackoverflow for a discussion on retrieving the containerId. See ControlGroup for the original version of this. Not much is actually left but it provided good inspiration.
- Returns:
- The container id.
-