Container Detect
Detect if your Python process is running inside a container. Supports Docker, Podman, Kubernetes, containerd, LXC, and more. Inspired by the popular is-inside-container npm package. Supports cached results with optional refresh.
Features
- Fast and reliable container detection for multiple container types
- Supports Docker, Podman, Kubernetes, containerd, LXC, and more
- Multiple detection methods for robustness
- Cached results for performance optimization
- Zero dependencies, minimal overhead
- Type hints for better IDE support
- Graceful error handling
Supported Container Types
- Docker - Classic Docker containers
- Podman - Podman containers
- Kubernetes - Kubernetes pods
- containerd - containerd containers
- LXC - Linux Containers
- CRI-O - Container Runtime Interface
- AWS ECS - Amazon Elastic Container Service
- And more container runtimes
Installation
pip install container-detect
Or using uv:
uv add container-detect
Usage
Check if running inside a container
from container_detect import is_inside_container
if is_inside_container():
print("Running inside a container")
else:
print("Not running inside a container")
Force refresh cache
from container_detect import is_inside_container
# Use cached result (default)
is_inside_container() # Fast, uses cache
# Force a fresh check, bypassing cache
is_inside_container(force_refresh=True) # Performs new detection
Credits
This package is inspired by the is-inside-container (npm) npm package by Sindre Sorhus.
Changelog
See CHANGELOG.md for a detailed list of changes and version history.
Contributing
Contributions are welcome! Please read our Contributing Guide for details on our code of conduct, development setup, and the process for submitting pull requests.
Support
If you find this library useful, please consider:
- ⭐ Starring the repository on GitHub to help others discover it.
- 💖 Sponsoring to support ongoing maintenance and development.
Become a Sponsor on GitHub | Support on Patreon
License
MIT License - see LICENSE file for details.
Author
Y. Siva Sai Krishna
- GitHub: @ysskrishna
- LinkedIn: ysskrishna
Metadata
Release files for container-detect 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| container_detect-1.0.0.tar.gz | 18.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| container_detect-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.0 kB
Release files / container_detect-1.0.0.tar.gz
| Download URL | container_detect-1.0.0.tar.gz |
|---|---|
| Size | 18.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2dc4ed70dcc6aabac32a568d2ff9d508f8d5391c9af1b77fbec7083d86d4a878
|
|
BLAKE2b-256 checksum How to use checksums |
2deba7550d3557bb6ea4aefe57fff4c5d8a7572fbe05d0dc4b68797e6d9819c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / container_detect-1.0.0-py3-none-any.whl
| Download URL | container_detect-1.0.0-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dac566c42b22500cfd4db47b35bcc53433b37985bb27fb0b6abcb4e901175c96
|
|
BLAKE2b-256 checksum How to use checksums |
9b535e60520e1220ea5131aaf680b8d50193713df8825ad36014373bd7f3c95a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|