docker
A Python library for the Docker Engine API.
Description
# Docker SDK for Python [](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
| Version | Changes | Urgency | Date |
|---|---|---|---|
| 7.1.0 | Imported from PyPI (7.1.0) | Low | 4/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 - Webs | Low | 12/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 co | Low | 12/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 | Low | 11/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 clien | Low | 11/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.3 | Low | 6/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 * @ImogenBit | Low | 5/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 co | Low | 5/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 2 | Low | 5/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 https | Low | 11/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 `__versi | Low | 8/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 Swarm | Low | 8/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/do | Low | 7/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 | Low | 10/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 | Low | 9/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.0 | Low | 8/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 | Low | 4/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 client | Low | 2/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 client | Low | 2/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 | Low | 2/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 | Low | 1/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 | Low | 11/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 | Low | 8/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 | Low | 8/10/2020 |
| 4.2.2 | 4.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 endpoints | Low | 6/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 optional | Low | 6/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` | Low | 2/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.3 | Low | 10/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-client | Low | 6/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 repaired | Low | 5/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` | Low | 5/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 TLS | Low | 3/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 others | Low | 3/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 paramete | Low | 1/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 path | Low | 11/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 | Low | 10/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_se | Low | 8/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` files | Low | 8/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 | Low | 6/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 fo | Low | 4/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. | Low | 3/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 `Dock | Low | 3/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 archives | Low | 3/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 | Low | 3/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 | Low | 3/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 | Low | 2/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 | Low | 2/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` and | Low | 2/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.contai | Low | 12/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. | Low | 12/19/2017 |
