Skip to content

Commit ca886f9

Browse files
authored
Merge pull request #1400 from scop/dockerenv
Detect Docker also using /.dockerenv
2 parents f848ee3 + 70a8f58 commit ca886f9

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

internal/common/common.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,10 @@ func HostDev(combineWith ...string) string {
364364
return GetEnv("HOST_DEV", "/dev", combineWith...)
365365
}
366366

367+
func HostRoot(combineWith ...string) string {
368+
return GetEnv("HOST_ROOT", "/", combineWith...)
369+
}
370+
367371
// getSysctrlEnv sets LC_ALL=C in a list of env vars for use when running
368372
// sysctl commands (see DoSysctrl).
369373
func getSysctrlEnv(env []string) []string {

internal/common/common_linux.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ func VirtualizationWithContext(ctx context.Context) (string, string, error) {
259259
}
260260
}
261261

262+
if PathExists(HostRoot(".dockerenv")) {
263+
system = "docker"
264+
role = "guest"
265+
}
266+
262267
// before returning for the first time, cache the system and role
263268
cachedVirtOnce.Do(func() {
264269
cachedVirtMutex.Lock()

0 commit comments

Comments
 (0)