Detect if your Python process is running inside a Docker container. Inspired by the popular is-docker npm package. Supports cached results with optional refresh.
- Fast and reliable Docker container detection
- Multiple detection methods for robustness
- Cached results for performance optimization
- Zero dependencies, minimal overhead
- Type hints for better IDE support
pip install docker-detectorOr using uv:
uv add docker-detectorfrom docker_detector import is_docker
if is_docker():
print("Running inside a Docker container")
else:
print("Not running inside a Docker container")from docker_detector import is_docker
# Use cached result (default)
is_docker() # Fast, uses cache
# Force a fresh check, bypassing cache
is_docker(force_refresh=True) # Performs new detectionThis package is inspired by the is-docker npm package by Sindre Sorhus.
See CHANGELOG.md for a detailed list of changes and version history.
Contributions are welcome! Please read our Contributing Guide for details on our code of conduct, development setup, and the process for submitting pull requests.
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
MIT License - see LICENSE file for details.
Y. Siva Sai Krishna
- GitHub: @ysskrishna
- LinkedIn: ysskrishna

