Your config should not depend on where the image last ran.
You ship the same Python service to a laptop, a CI worker, and a cluster. Somewhere along the way you need a honest answer: are we inside a container right now? A Docker-only check misreads Podman and many Kubernetes layouts. A custom env var you baked into one Dockerfile disappears on the next runtime. You end up pasting snippets from three forum threads and hoping they still match cgroup v2.
Container Detect gives you one function that aims for broad container detection behind a single entry point.
Know the runtime before you branch the config.
What you get
- One answer across runtimes. The docs call out Docker, Podman, Kubernetes, containerd, LXC, CRI-O, AWS ECS, and more container runtimes.
- Several signals, not one brittle trick. Multiple detection methods combine cgroup reads, marker files, mount patterns, and environment variables so one missing file does not decide everything.
- Cached by default. Cached results keep repeated checks cheap; pass force_refresh when the environment just changed and you need a fresh read.
- Fails quietly. Graceful error handling means a filesystem probe that fails does not crash your process.
- Nothing else to install. Zero dependencies, minimal overhead, Python 3.8 or newer.
- Free and open source. MIT licensed, published on PyPI.
Picture your Monday
An illustrative case: your logging setup writes verbose traces on a developer laptop but stays quiet inside production images. At startup the app asks whether it is inside a container and picks the profile. The same branch works whether the image landed on Docker Desktop, a Podman build farm, or a Kubernetes node, as long as the process runs on Linux.
Ready to try it?
- See it on GitHub for how detection is implemented and tested
- Get it on PyPI
Need a narrower Docker-only check? Docker Detector covers the classic Docker case on the same site.






