fix(core): Update isDocker check to return true on kubernetes/containerd (#12603)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2025-01-17 13:10:51 +01:00
committed by GitHub
parent 7ae1483792
commit c55dac66ed
2 changed files with 57 additions and 21 deletions

View File

@@ -142,19 +142,30 @@ export class InstanceSettings {
}
/**
* Whether this instance is running inside a Docker container.
*
* Based on: https://github.com/sindresorhus/is-docker
* Whether this instance is running inside a Docker/Podman/Kubernetes container.
*/
@Memoized
get isDocker() {
if (existsSync('/.dockerenv') || existsSync('/run/.containerenv')) return true;
try {
return (
existsSync('/.dockerenv') || readFileSync('/proc/self/cgroup', 'utf8').includes('docker')
);
} catch {
return false;
}
const cgroupV1 = readFileSync('/proc/self/cgroup', 'utf8');
if (
cgroupV1.includes('docker') ||
cgroupV1.includes('kubepods') ||
cgroupV1.includes('containerd')
)
return true;
} catch {}
try {
const cgroupV2 = readFileSync('/proc/self/mountinfo', 'utf8');
if (
cgroupV2.includes('docker') ||
cgroupV2.includes('kubelet') ||
cgroupV2.includes('containerd')
)
return true;
} catch {}
return false;
}
update(newSettings: WritableSettings) {