From 7661b65df48639b527435b1d42b630c93c9720a4 Mon Sep 17 00:00:00 2001 From: MasutaYunikon Date: Mon, 20 Apr 2026 22:30:07 +0200 Subject: [PATCH] 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. --- server/config.ts | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/server/config.ts b/server/config.ts index 5520130..7615319 100644 --- a/server/config.ts +++ b/server/config.ts @@ -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') \ No newline at end of file + : path.join(BASE_DIR, 'config'); \ No newline at end of file