Best-effort container runtime detection.
()
| 12 | |
| 13 | |
| 14 | def _running_in_container() -> bool: |
| 15 | """Best-effort container runtime detection.""" |
| 16 | if Path("/.dockerenv").exists() or Path("/run/.containerenv").exists(): |
| 17 | return True |
| 18 | |
| 19 | cgroup = Path("/proc/1/cgroup") |
| 20 | if not cgroup.exists(): |
| 21 | return False |
| 22 | |
| 23 | try: |
| 24 | content = cgroup.read_text(encoding="utf-8", errors="ignore") |
| 25 | except OSError: |
| 26 | return False |
| 27 | |
| 28 | return any(token in content for token in ("docker", "containerd", "kubepods", "podman")) |
| 29 | |
| 30 | |
| 31 | def _default_agent_data_dir() -> str: |
no test coverage detected