Skip to content
Permalink
Browse files
fix(buildah): improve whether we are in container detection
Signed-off-by: Ilya Lesikov <ilya@lesikov.com>
  • Loading branch information
ilya-lesikov committed Jun 17, 2022
1 parent 603944f commit 532a002494963a024d34fb550a8126dd7d4f4933
Showing 1 changed file with 12 additions and 2 deletions.
@@ -48,9 +48,19 @@ func IsInContainer() bool {
return true
}

cgroupsData, err := os.ReadFile("/proc/1/cgroup")
if err != nil {
return false
}

// containerd without Docker-daemon
if cgroupsData, err := os.ReadFile("/proc/1/cgroup"); err == nil &&
strings.Contains(string(cgroupsData), "/cri-containerd-") {
if strings.Contains(string(cgroupsData), "/cri-containerd-") ||
strings.Contains(string(cgroupsData), "/containerd") {
return true
}

// If in Kubernetes
if strings.Contains(string(cgroupsData), "/kubepods") {
return true
}

0 comments on commit 532a002

Please sign in to comment.