How to Install docker in Python
A Python library for the Docker Engine API.
pip install docker
What is docker?
A Python library for the Docker Engine API.
A Python library for the Docker Engine API. It lets you do anything the command does, but from within Python apps – run containers, manage containers, manage Swarms, etc.
The latest stable version is available on PyPI. Install with pip:
> Older versions ( This is no longer necessary and is a no-op, but is supported for backwards compatibility.
Quick Start
Minimal example to get started with docker:
import docker
print(docker.__version__)
Installation
pip (standard)
pip install docker
Virtual environment (recommended)
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install docker
pip3
pip3 install docker
conda
conda install -c conda-forge docker
Poetry
poetry add docker
Dependencies
Installing docker will also install these packages:
Verify the Installation
After installing, confirm the package is available:
python -c "import docker; print(docker.__version__)"
If this prints a version number, installation succeeded. If you see a ModuleNotFoundError, see the errors section below.
Installation Errors
Common errors when installing docker with pip.
ModuleNotFoundError: No module named 'docker'
Cause: The package is not installed in the current Python environment.
Fix: Run pip install docker. If using a virtual environment, ensure it is activated first.
ModuleNotFoundError: No module named 'docker' (installed but still failing)
Cause: pip installed the package into a different Python than the one running your script.
Fix: Use python -m pip install docker to install into the interpreter you are running.
ImportError: cannot import name 'X' from 'docker'
Cause: The function or class does not exist in the installed version.
Fix: Check the version with pip show docker and upgrade with pip install --upgrade docker.
pip: command not found
Cause: pip is not in PATH or Python was not added to PATH during installation.
Fix: Try python -m pip install docker. On macOS/Linux try pip3.
PermissionError: [Errno 13] Permission denied
Cause: No write access to the system Python package directory.
Fix: Use a virtual environment, or add --user: pip install --user docker
SSL: CERTIFICATE_VERIFY_FAILED
Cause: pip cannot verify PyPI's SSL certificate — common behind corporate proxies.
Fix: Try: pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org docker
Recent Releases
| Version | Released |
|---|---|
7.1.0 latest |
2024-05-23 |
7.0.0 |
2023-12-08 |
7.0.0b3 |
2023-12-05 |
7.0.0b2 |
2023-11-27 |
6.1.3 |
2023-06-01 |
Manage docker
Upgrade to latest version
pip install --upgrade docker
Install a specific version
pip install docker==7.1.0
Uninstall
pip uninstall docker
Check what is installed
pip show docker