freshcrate
Skin:/
Home > Frameworks > docker

docker

A Python library for the Docker Engine API.

Why this rank:Strong adoptionRelease freshnessHealthy release cadence

Description

# Docker SDK for Python [![Build Status](https://github.com/docker/docker-py/actions/workflows/ci.yml/badge.svg)](https://github.com/docker/docker-py/actions/workflows/ci.yml) A Python library for the Docker Engine API. It lets you do anything the `docker` command does, but from within Python apps – run containers, manage containers, manage Swarms, etc. ## Installation The latest stable version [is available on PyPI](https://pypi.python.org/pypi/docker/). Install with pip: pip install docker > Older versions (< 6.0) required installing `docker[tls]` for SSL/TLS support. > This is no longer necessary and is a no-op, but is supported for backwards compatibility. ## Usage Connect to Docker using the default socket or the configuration in your environment: ```python import docker client = docker.from_env() ``` You can run containers: ```python >>> client.containers.run("ubuntu:latest", "echo hello world") 'hello world\n' ``` You can run containers in the background: ```python >>> client.containers.run("bfirsh/reticulate-splines", detach=True) <Container '45e6d2de7c54'> ``` You can manage containers: ```python >>> client.containers.list() [<Container '45e6d2de7c54'>, <Container 'db18e4f20eaa'>, ...] >>> container = client.containers.get('45e6d2de7c54') >>> container.attrs['Config']['Image'] "bfirsh/reticulate-splines" >>> container.logs() "Reticulating spline 1...\n" >>> container.stop() ``` You can stream logs: ```python >>> for line in container.logs(stream=True): ... print(line.strip()) Reticulating spline 2... Reticulating spline 3... ... ``` You can manage images: ```python >>> client.images.pull('nginx') <Image 'nginx'> >>> client.images.list() [<Image 'ubuntu'>, <Image 'nginx'>, ...] ``` [Read the full documentation](https://docker-py.readthedocs.io) to see everything you can do.

Release History

VersionChangesUrgencyDate
7.1.0Imported from PyPI (7.1.0)Low4/21/2026
7.0.0## Upgrade Notes (from 6.x) âš ī¸ - Removed SSL version (`ssl_version`) and explicit hostname check (`assert_hostname`) options (#3185) - `assert_hostname` has not been used since Python 3.6 and was removed in 3.12 - Python 3.7+ supports TLSv1.3 by default - Websocket support is no longer included by default (#3123) - Use `pip install docker[websockets]` to include `websocket-client` dependency - By default, `docker-py` hijacks the TCP connection and does not use Websockets - WebsLow12/8/2023
7.0.0b3**â„šī¸ See 7.0.0b2 for full release notes** ## Upgrade Notes (from 6.x) âš ī¸ - Removed SSL version (`ssl_version`) and explicit hostname check (`assert_hostname`) options (#3185) - `assert_hostname` has not been used since Python 3.6 and was removed in 3.12 - Python 3.7+ supports TLSv1.3 by default - Websocket support is no longer included by default (#3123) - Use `pip install docker[websockets]` to include `websocket-client` dependency - By default, `docker-py` hijacks the TCP coLow12/5/2023
7.0.0b2â„šī¸ **This is identical to `7.0.0b1`, which was not correctly released due to a CI pipeline issue.** ## Upgrade Notes âš ī¸ - Removed SSL version (`ssl_version`) and explicit hostname check (`assert_hostname`) options (#3185) - `assert_hostname` has not been used since Python 3.6 and was removed in 3.12 - Python 3.7+ supports TLSv1.3 by default - Websocket support is no longer included by default (#3123) - Use `pip install docker[websockets]` to include `websocket-client` dependency Low11/27/2023
7.0.0b1## Upgrade Notes âš ī¸ - Removed SSL version (`ssl_version`) and explicit hostname check (`assert_hostname`) options (#3185) - `assert_hostname` has not been used since Python 3.6 and was removed in 3.12 - Python 3.7+ supports TLSv1.3 by default - Websocket support is no longer included by default (#3123) - Use `pip install docker[websockets]` to include `websocket-client` dependency - By default, `docker-py` hijacks the TCP connection and does not use Websockets - Websocket clienLow11/21/2023
6.1.3## 🐛 Bugfixes * Fix eventlet compatibility (#3132) ## What's Changed * fix: eventlet compatibility by @tito in https://github.com/docker/docker-py/pull/3132 ## New Contributors * @tito made their first contribution in https://github.com/docker/docker-py/pull/3132 **Full Changelog**: https://github.com/docker/docker-py/compare/6.1.2...6.1.3Low6/1/2023
6.1.2## 🐛 Bugfixes * Fix for socket timeouts on long `docker exec` calls (#3125) * Respect `timeout` param on Windows (#3112) ## Full Changelog * Use windows api to honour timeouts (fixes #3111) by @ImogenBits in https://github.com/docker/docker-py/pull/3112 * Avoid socket timeouts when executing commands by @loicleyendecker in https://github.com/docker/docker-py/pull/3125 * docs: update changelog by @milas in https://github.com/docker/docker-py/pull/3127 ## New Contributors * @ImogenBitLow5/11/2023
6.1.1## â„šī¸ Upgrade Notes (6.1.x) - Errors are no longer returned during client initialization if the credential helper cannot be found. A warning will be emitted instead, and an error is returned if the credential helper is used. ## 🐛 Bugfixes - Fix `containers.stats()` hanging with `stream=True` - Correct return type in docs for `containers.diff()` method ## What's Changed * api: update return type of `diff` method by @john-b-yang in https://github.com/docker/docker-py/pull/3115 * Fix coLow5/8/2023
6.1.0## â„šī¸ Upgrade Notes - Errors are no longer returned during client initialization if the credential helper cannot be found. A warning will be emitted instead, and an error is returned if the credential helper is used. ## ✨ Features - Python 3.11 support - Use `poll()` instead of `select()` on non-Windows platforms - New API fields - `network_driver_opt` on container run / create - `one-shot` on container stats - `status` on services list ## 🐛 Bugfixes - Support for requests 2Low5/5/2023
6.0.1## âš ī¸ Notice This version is not compatible with `requests` 2.29+ or `urllib3` 2.x. Either add `requests < 2.29` and `urllib3 < 2` to your requirements or upgrade to to the [latest `docker-py` release](https://github.com/docker/docker-py/releases/latest). ## 🐛 Bugfixes * Fix for `The pipe has been ended` errors on Windows (#3056) * Support floats for timestamps in Docker logs (`since` / `until`) (#3031) ## What's Changed * docs: install package in ReadTheDocs build by @milas in httpsLow11/2/2022
6.0.0### â„šī¸ Upgrade Notes - Minimum supported Python version is 3.7+ - When installing with pip, the `docker[tls]` extra is deprecated and a no-op, use `docker` for same functionality (TLS support is always available now) - Native Python SSH client (used by default / `use_ssh_client=False`) will now reject unknown host keys with `paramiko.ssh_exception.SSHException` - Short IDs are now 12 characters instead of 10 characters (same as Docker CLI) - Version metadata is now exposed as `__versiLow8/18/2022
6.0.0b2## What's Changed * remove duplicate 'on' in comment by @thomasgassmann in https://github.com/docker/docker-py/pull/2370 * Add `gzip` documentation to `BuildApiMixin` by @SauravMaheshkar in https://github.com/docker/docker-py/pull/2929 * Use `preexec_func` always by @q0w in https://github.com/docker/docker-py/pull/2920 * Remove docker.credentials.utils.find_executable by @n1ngu in https://github.com/docker/docker-py/pull/3028 * Support `global-job` and `replicated-job` modes in Docker SwarmLow8/11/2022
6.0.0b1## What's Changed * Update changelog for 5.0.3 by @aiordache in https://github.com/docker/docker-py/pull/2897 * Add support for Python 3.10 by @hugovk in https://github.com/docker/docker-py/pull/2898 * Bump paramiko from 2.8.0 to 2.10.1 by @dependabot in https://github.com/docker/docker-py/pull/2974 * deps: upgrade pywin32 & relax version constraint by @milas in https://github.com/docker/docker-py/pull/3004 * ci: remove Python 3.6 and add 3.11 pre-releases by @milas in https://github.com/doLow7/30/2022
5.0.3 [List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/76?closed=1) ## Features - Add `cap_add` and `cap_drop` parameters to service create and ContainerSpec - Add `templating` parameter to config create ## Bugfixes - Fix getting a read timeout for logs/attach with a tty and slow output ## Miscellaneous - Fix documentation examples Low10/7/2021
5.0.2[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/75?closed=1) ## Bugfixes - Fix `disable_buffering` regression Low9/1/2021
5.0.1[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/74?closed=1) ## Bugfixes - Bring back support for ssh identity file - Cleanup remaining python-2 dependencies - Fix image save example in docs ## Miscellaneous - Bump urllib3 to 1.26.5 - Bump requests to 2.26.0Low8/31/2021
5.0.0[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/70?closed=1) ## Breaking changes - Remove support for Python 2.7 - Make Python 3.6 the minimum version supported ## Features - Add `limit` parameter to image search endpoint ## Bugfixes - Fix `KeyError` exception on secret create - Verify TLS keys loaded from docker contexts - Update PORT_SPEC regex to allow square brackets for IPv6 addresses - Fix containers and images documentation examples Low4/6/2021
4.4.4> ## Warning > This is the last release with support for Python 2.7 and 3.5 [List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/73?closed=1) ### Bugfixes - Remove `LD_LIBRARY_PATH` and `SSL_CERT_FILE` environment variables when shelling out to the ssh clientLow2/24/2021
4.4.3[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/72?closed=1) ### Features - Add support for docker.types.Placement.MaxReplicas ### Bugfixes - Fix SSH port parsing when shelling out to the ssh clientLow2/18/2021
4.4.2[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/71?closed=1) ### Bugfixes - Fix SSH connection bug where the hostname was incorrectly trimmed and the error was hidden - Fix docs example ### Miscellaneous - Add Python3.8 and 3.9 in setup.py classifier list Low2/15/2021
4.4.1[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/69?closed=1) ### Bugfixes - Avoid setting unsupported parameter for subprocess.Popen on Windows Low1/7/2021
4.4.0[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/67?closed=1) ### Features - Add an alternative SSH connection to the paramiko one, based on shelling out to the SSh client. Similar to the behaviour of Docker cli - Default image tag to `latest` on `pull` ### Bugfixes - Fix plugin model upgrade - Fix examples URL in ulimits ### Miscellaneous - Improve exception messages for server and client errors - Bump cryptography from 2.3 to 3.2 Low11/23/2020
4.3.1[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/68?closed=1) ### Miscellaneous - Set default API version to `auto` - Fix conversion to bytes for `float` - Support OpenSSH `identityfile` option Low8/21/2020
4.3.0# Changelog ### Features - Add `DeviceRequest` type to expose host resources such as GPUs - Add support for `DriverOpts` in EndpointConfig - Disable compression by default when using container.get_archive method ### Miscellaneous - Update default API version to v1.39 - Update test engine version to 19.03.12 Low8/10/2020
4.2.24.2.2 ----- [List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/66?closed=1) ### Bugfixes - Fix context load for non-docker endpointsLow6/30/2020
4.2.1[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/65?closed=1) ### Features - Add option on when to use `tls` on Context constructor - Make context orchestrator field optionalLow6/2/2020
4.2.0[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/63?closed=1) ### Bugfixes - Fix `win32pipe.WaitNamedPipe` throw exception in Windows containers - Use `Hostname`, `Username`, `Port` and `ProxyCommand` settings from `.ssh/config` when on SSH - Set host key policy for ssh transport to `paramiko.WarningPolicy()` - Set logging level of `paramiko` to warn ### Features - Add support for docker contexts through `docker.ContextAPI`Low2/6/2020
4.1.0[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/61?closed=1) ### Bugfixes - Correct `INDEX_URL` logic in build.py _set_auth_headers - Fix for empty auth keys in config.json ### Features - Add `NetworkAttachmentConfig` for service create/update ### Miscellaneous - Bump pytest to 4.3.1 - Adjust `--platform` tests for changes in docker engine - Update credentials-helpers to v0.6.3Low10/3/2019
4.0.2[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/62?closed=1) ### Bugfixes - Unified the way `HealthCheck` is created/configured ### Miscellaneous - Bumped version of websocket-clientLow6/20/2019
4.0.1[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/60?closed=1) ### Bugfixes - Fixed an obsolete import in the `credentials` subpackage that caused import errors in Python 3.7 ### Miscellaneous - Docs building has been repairedLow5/19/2019
4.0.0[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/57?closed=1) ### Breaking changes - Support for Python 3.3 and Python 3.4 has been dropped - `APIClient.update_service`, `APIClient.init_swarm`, and `DockerClient.swarm.init` now return a `dict` from the API's response body - In `APIClient.build` and `DockerClient.images.build`, the `use_config_proxy` parameter now defaults to True - `init_path` is no longer a valid parameter for `HostConfig` Low5/19/2019
3.7.2[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/59?closed=1) ### Bugfixes * Fix base_url to keep TCP protocol on utils.py by letting the responsability of changing the protocol to `parse_host` afterwards, letting `base_url` with the original value. * XFAIL test_attach_stream_and_cancel on TLSLow3/28/2019
3.7.1[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/58?closed=1) ### Bugfixes * Set a different default number (which is now 9) for SSH pools * Adds a BaseHTTPAdapter with a close method to ensure that the pools is clean on close() * Makes SSHHTTPAdapter reopen a closed connection when needed like the othersLow3/20/2019
3.7.0[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/56?closed=1) ### Features * Added support for multiplexed streams (for `attach` and `exec_start`). Learn more at https://docker-py.readthedocs.io/en/stable/user_guides/multiplex.html * Added the `use_config_proxy` parameter to the following methods: `APIClient.build`, `APIClient.create_container`, `DockerClient.images.build` and `DockerClient.containers.run` (`False` by default). **This parameteLow1/10/2019
3.6.0[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone=55?closed=1) ### Features * Added support for connecting to the Docker Engine over SSH. Additional dependencies for this feature can be installed with `pip install "docker[ssh]"` * Added support for the `named` parameter in `Image.save`, which may be used to ensure the resulting tarball retains the image's name on save. ### Bugfixes * Fixed a bug where builds on Windows with a context pathLow11/28/2018
3.5.1 [List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/54?closed=1) ### Miscellaneous * Bumped version of `pyOpenSSL` in `requirements.txt` and `setup.py` to prevent installation of a vulnerable version * Docs fixes Low10/17/2018
3.5.0[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone=53?closed=1) ### Deprecation warning * Support for Python 3.3 will be dropped in the 4.0.0 release ### Features * Updated dependencies to ensure support for Python 3.7 environments * Added support for the `uts_mode` parameter in `HostConfig` * The `UpdateConfig` constructor now allows `rollback` as a valid value for `failure_action` * Added support for `rollback_config` in `APIClient.create_seLow8/10/2018
3.4.1[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/52?closed=1) ### Bugfixes * Fixed a bug that caused auth values in config files written using one of the legacy formats to be ignored * Fixed issues with handling of double-wildcard `**` patterns in `.dockerignore` filesLow8/9/2018
3.4.0[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/51?closed=1) ### Features * The `APIClient` and `DockerClient` constructors now accept a `credstore_env` parameter. When set, values in this dictionary are added to the environment when executing the credential store process. ### Bugfixes * `DockerClient.networks.prune` now properly returns the operation's result * Fixed a bug that caused custom Dockerfile paths in a subfolder of the build Low6/18/2018
3.3.0[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/49?closed=1) ### Features * Added support for `prune_builds` in `APIClient` and `DockerClient.images` * Added support for `ignore_removed` parameter in `DockerClient.containers.list` ### Bugfixes * Fixed an issue that caused builds to fail when an in-context Dockerfile would be specified using its absolute path * Installation with pip 10.0.0 and above no longer fails * Connection timeout foLow4/26/2018
3.2.1[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/50?closed=1) ### Bugfixes * Fixed a bug with builds not properly identifying Dockerfile paths relative to the build context * Fixed an issue where builds would raise a `ValueError` when attempting to build with a Dockerfile on a different Windows drive.Low3/30/2018
3.2.0[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/45?closed=1) ### Features * Generators returned by `attach()`, `logs()` and `events()` now have a `cancel()` method to let consumers stop the iteration client-side. * `build()` methods can now handle Dockerfiles supplied outside of the build context. * Added `sparse` argument to `DockerClient.containers.list()` * Added `isolation` parameter to `build()` methods. * Added `close()` method to `DockLow3/29/2018
3.1.4[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/48?closed=1) ### Bugfixes * Fixed a bug where build contexts containing directory symlinks would produce invalid tar archivesLow3/21/2018
3.1.3[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/47?closed=1) ### Bugfixes * Fixed a bug that led to a Dockerfile not being included in the build context in some situations when the Dockerfile's path was prefixed with `./` * Regenerated invalid wheel package Low3/20/2018
3.1.1[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/46?closed=1) ### Bugfixes * Fixed a bug that caused costly DNS lookups on Mac OSX when connecting to the engine through UNIX socket * Fixed a bug that caused `.dockerignore` comments to be read as exclusion patterns Low3/5/2018
3.1.0[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/44?closed=1) ### Features * Added support for `device_cgroup_rules` in host config * Added support for `generic_resources` when creating a `Resources` object. * Added support for a configurable `chunk_size` parameter in `export`, `get_archive` and `get_image` (`Image.save`) * Added a `force_update` method to the `Service` class. * In `Service.update`, when the `force_update` parameter is set to Low2/22/2018
3.0.1[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/43?closed=1) ### Bugfixes * Fixed a bug where `APIClient.login` didn't populate the `_auth_configs` dictionary properly, causing subsequent `pull` and `push` operations to fail * Fixed a bug where some build context files were incorrectly recognized as being inaccessible. * Fixed a bug where files with a negative mtime value would cause errors when included in a build context Low2/5/2018
3.0.0[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/39?closed=1) ### Breaking changes * Support for API version < 1.21 has been removed. * The following methods have been removed: * `APIClient.copy` has been removed. Users should use `APIClient.get_archive` instead. * `APIClient.insert` has been removed. Users may use `APIClient.put_archive` combined with `APIClient.commit` to replicate the method's behavior. * `utils.ping_registry` andLow2/1/2018
2.7.0[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/41?closed=1) ### Features * Added `unlock_swarm` and `get_unlock_key` methods to the `APIClient`. * Added `unlock` and `get_unlock_key` to `DockerClient.swarm`. * Added a `greedy` parameter to `DockerClient.networks.list`, yielding additional details about the listed networks. * Added `cpu_rt_runtime` and `cpu_rt_period` as parameters to `APIClient.create_host_config` and `DockerClient.contaiLow12/19/2017
2.6.1[List of PRs / issues for this release](https://github.com/docker/docker-py/milestone/40?closed=1) ### Bugfixes * Fixed a bug on Python 3 installations preventing the use of the `attach` and `exec_run` methods.Low12/19/2017

Dependencies & License Audit

Loading dependencies...

Similar Packages

tqdmFast, Extensible Progress Meterv4.68.1
inspect-aiFramework for large language model evaluationsmain@2026-06-05
hypothesisThe property-based testing library for Pythonv6.155.2
bleachAn easy safelist-based HTML-sanitizing tool.main@2026-06-05
jupyter-clientJupyter protocol implementation and client librariesv8.9.0

More from pypi

markitdownUtility tool for converting various files to Markdown
fastapiFastAPI framework, high performance, easy to learn, fast to code, ready for production
djangoA high-level Python web framework that encourages rapid development and clean, pragmatic design.
flaskA simple framework for building complex web applications.

More in Frameworks

langchainThe agent engineering platform
deer-flowAn open-source long-horizon SuperAgent harness that researches, codes, and creates. With the help of sandboxes, memories, tools, skill, subagents and message gateway, it handles different levels of ta
tqdmFast, Extensible Progress Meter
simBuild, deploy, and orchestrate AI agents. Sim is the central intelligence layer for your AI workforce.