hostinfo: detect being run in a container in more ways

Change-Id: I038ff7705ba232e6cf8dcc9775357ef708d43762
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
(cherry picked from commit 16939f0d56)
This commit is contained in:
Brad Fitzpatrick 2022-09-11 21:45:08 -07:00 committed by Brad Fitzpatrick
parent facdc475bb
commit 0345649d05

View File

@ -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/")) ||