Skip to content

Commit

Permalink
Detect Docker also using /.dockerenv
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Dec 28, 2022
1 parent f848ee3 commit 70a8f58
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/common/common.go
Expand Up @@ -364,6 +364,10 @@ func HostDev(combineWith ...string) string {
return GetEnv("HOST_DEV", "/dev", combineWith...)
}

func HostRoot(combineWith ...string) string {
return GetEnv("HOST_ROOT", "/", combineWith...)
}

// getSysctrlEnv sets LC_ALL=C in a list of env vars for use when running
// sysctl commands (see DoSysctrl).
func getSysctrlEnv(env []string) []string {
Expand Down
5 changes: 5 additions & 0 deletions internal/common/common_linux.go
Expand Up @@ -259,6 +259,11 @@ func VirtualizationWithContext(ctx context.Context) (string, string, error) {
}
}

if PathExists(HostRoot(".dockerenv")) {
system = "docker"
role = "guest"
}

// before returning for the first time, cache the system and role
cachedVirtOnce.Do(func() {
cachedVirtMutex.Lock()
Expand Down

0 comments on commit 70a8f58

Please sign in to comment.