Skip to content

Commit

Permalink
Merge pull request #4553 from werf/fix-improve-container-detection
Browse files Browse the repository at this point in the history
fix(buildah): improve whether we are in container detection
  • Loading branch information
ilya-lesikov committed Jun 17, 2022
2 parents 603944f + 532a002 commit c9b39c8
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 c9b39c8

Please sign in to comment.