From 70a8f589c664bd221f829623d6803eed6021dba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Wed, 28 Dec 2022 23:12:58 +0200 Subject: [PATCH] Detect Docker also using /.dockerenv --- internal/common/common.go | 4 ++++ internal/common/common_linux.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/internal/common/common.go b/internal/common/common.go index 9cb752bbd..323402dcf 100644 --- a/internal/common/common.go +++ b/internal/common/common.go @@ -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 { diff --git a/internal/common/common_linux.go b/internal/common/common_linux.go index 3b4de8e53..fa6373b55 100644 --- a/internal/common/common_linux.go +++ b/internal/common/common_linux.go @@ -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()