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.
Project description
Docker Detector
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
- GitHub: @ysskrishna
- LinkedIn: ysskrishna
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file docker_detector-1.0.1.tar.gz.
File metadata
- Download URL: docker_detector-1.0.1.tar.gz
- Upload date:
- Size: 15.8 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
087136388e0e533a40897212df49d39c5acdecfcbe6bd95e736a08369373c0d9
|
|
| MD5 |
354ecb08783eb0db37ca2c55b1d9d029
|
|
| BLAKE2b-256 |
972c636fdba56f7047ece3efd184bb987e85ffedd515d6539d88882bd19835c2
|
File details
Details for the file docker_detector-1.0.1-py3-none-any.whl.
File metadata
- Download URL: docker_detector-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b4cf0835aaf65f3df3df6f3435afbe289a2f80063aef2de9f3152dd7bbf66cc
|
|
| MD5 |
0c6eb9943eac23cd7e0240878bbce7e2
|
|
| BLAKE2b-256 |
73c1b3e32ef116a4b0fbb93eb14d19a1a9767467506e75fc154174e3959aa95d
|