Documentation
¶
Overview ¶
Package selfid discovers, without contacting the Docker Engine, the candidate container IDs the current process might be running as.
It deliberately returns UNVERIFIED candidates in priority order. No single source is reliable: /proc/self/cgroup reports a bare "0::/" under cgroup v2 with a private namespace (the modern Docker default), $HOSTNAME is the short ID only until someone passes --hostname, and mountinfo depends on the storage driver. Verification needs the Engine, so it happens in internal/dockerx (D2, D6).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Result ¶
type Result struct {
// Containerized reports whether this process is running inside a Docker
// container, detected by /.dockerenv — which Docker creates in every
// container regardless of base image, including distroless/static.
Containerized bool
// Candidates are container-ID candidates in priority order, longest and
// most trustworthy first. May be empty even when Containerized is true.
Candidates []string
// Override is the operator-supplied DEVMON_SELF_CONTAINER_ID, or "" when
// none was set. Carried alongside Candidates (rather than requiring the
// caller to remember it separately) so internal/dockerx's confirmSelf can
// tell whether a skipped candidate was the operator's explicit choice and
// log accordingly.
Override string
}
Result is what Detect could learn from the filesystem alone.
func Detect ¶
Detect gathers candidates. root is the filesystem root to read under ("/" in production, a temp dir in tests). override, when non-empty, is the operator's DEVMON_SELF_CONTAINER_ID and always sorts first. getenv is a parameter rather than a call to os.Getenv so callers can inject a fake environment in tests without t.Setenv, which forbids t.Parallel.