fix: improve container detection to support Podman and other runtimes

Replace single /.dockerenv check with a robust isInContainer() helper
that covers Docker, Podman (/.containerenv), cgroup-based detection
(containerd, LXC) and /proc/1/environ as a general fallback.
This commit is contained in:
MasutaYunikon committed 2026-04-20 22:30:07 +02:00
1 parent 3847ba1c58
commit 7661b65df4
1 file changed
+24 -2
+24 -2
View File
@@ -8,6 +8,28 @@ export const BASE_DIR = _isBunBinary
? path.dirname((process as any).execPath)
: process.cwd()
export const DATA_DIR = fs.existsSync('/.dockerenv')
const isInContainer = (): boolean => {
// Docker
if (fs.existsSync('/.dockerenv')) return true;
// Podman (crée un fichier /.containerenv)
if (fs.existsSync('/.containerenv')) return true;
// Vérification via cgroup (Docker, Podman, LXC, etc.)
try {
const cgroup = fs.readFileSync('/proc/1/cgroup', 'utf8');
if (/docker|podman|containerd|lxc/i.test(cgroup)) return true;
} catch {}
// Vérification via /proc/1/environ (fallback général)
try {
const environ = fs.readFileSync('/proc/1/environ', 'utf8');
if (environ.includes('container=')) return true;
} catch {}
return false;
};
export const DATA_DIR = isInContainer()
? '/config'
: path.join(BASE_DIR, 'config')
: path.join(BASE_DIR, 'config');