From 0345649d0564813c80c031ca8c586743b055dc5c Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 11 Sep 2022 21:45:08 -0700 Subject: [PATCH] hostinfo: detect being run in a container in more ways Change-Id: I038ff7705ba232e6cf8dcc9775357ef708d43762 Signed-off-by: Brad Fitzpatrick (cherry picked from commit 16939f0d56e4543a5f9e3f9295a806029e8d45d0) --- hostinfo/hostinfo.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hostinfo/hostinfo.go b/hostinfo/hostinfo.go index ba03aae7f..31a9f922d 100644 --- a/hostinfo/hostinfo.go +++ b/hostinfo/hostinfo.go @@ -183,6 +183,13 @@ func inContainer() bool { if runtime.GOOS != "linux" { return false } + if _, err := os.Stat("/.dockerenv"); err == nil { + return true + } + if _, err := os.Stat("/run/.containerenv"); err == nil { + // See https://github.com/cri-o/cri-o/issues/5461 + return true + } var ret bool lineread.File("/proc/1/cgroup", func(line []byte) error { if mem.Contains(mem.B(line), mem.S("/docker/")) ||