Skip to main content

Detect if your Python process is running inside a Docker container — inspired by the popular is-docker npm package. Works on Linux, with optional cache refresh for repeated checks.

Project description

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. Works on Linux, with optional cache refresh for repeated checks.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docker_detector-1.0.0.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docker_detector-1.0.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file docker_detector-1.0.0.tar.gz.

File metadata

  • Download URL: docker_detector-1.0.0.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","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}

File hashes

Hashes for docker_detector-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e888953ad6a1d99c6cf8422f34480e0e24e99a783365ad7ee46cddad521e0419
MD5 cc841e32cf0b53925bfff7388c886782
BLAKE2b-256 ccf4486a3775faede78b19908cef2c6c954fad94702b81efabf65890fd00acfd

See more details on using hashes here.

File details

Details for the file docker_detector-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: docker_detector-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","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}

File hashes

Hashes for docker_detector-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 11e7a287d6977eca4ccb69738e63bd3142b2f91c854cfce239fab56b56ab4559
MD5 262c4846556f8a9964712af7be04de15
BLAKE2b-256 e40a413d1744d34c2b4129797bf523cdcbb2b695cdcd85d388ae0ac2981832d9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page