From 16939f0d56e4543a5f9e3f9295a806029e8d45d0 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 --- hostinfo/hostinfo.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hostinfo/hostinfo.go b/hostinfo/hostinfo.go index ca9ea718b..d7f239e7c 100644 --- a/hostinfo/hostinfo.go +++ b/hostinfo/hostinfo.go @@ -229,6 +229,15 @@ func inContainer() opt.Bool { } var ret opt.Bool ret.Set(false) + if _, err := os.Stat("/.dockerenv"); err == nil { + ret.Set(true) + return ret + } + if _, err := os.Stat("/run/.containerenv"); err == nil { + // See https://github.com/cri-o/cri-o/issues/5461 + ret.Set(true) + return ret + } lineread.File("/proc/1/cgroup", func(line []byte) error { if mem.Contains(mem.B(line), mem.S("/docker/")) || mem.Contains(mem.B(line), mem.S("/lxc/")) {