Skip to content

Repository files navigation

Docker Detector

Python Version License Tests PyPI PyPI Downloads

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.

Features

  • 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

Installation

pip install docker-detector

Or using uv:

uv add docker-detector

Usage

Check if running inside Docker

from docker_detector import is_docker

if is_docker():
    print("Running inside a Docker container")
else:
    print("Not running inside a Docker container")

Force refresh cache

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 detection

Credits

This package is inspired by the is-docker 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

About

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.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages