Skip to content

Commit

Permalink
fix(buildah): improve whether we are in container detection
Browse files Browse the repository at this point in the history
Signed-off-by: Ilya Lesikov <ilya@lesikov.com>
  • Loading branch information
ilya-lesikov committed Jun 17, 2022
1 parent 603944f commit 532a002
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/util/linux_container.go
Expand Up @@ -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
}

Expand Down

0 comments on commit 532a002

Please sign in to comment.