A Python library for the Docker Engine API
Go to file
Sebastiaan van Stijn e6a64e3671 Update default API version to v1.39 (#2512)
* Update default API version to v1.39

When running the docker-py integration tests in the Moby repository, some
tests were skipped because the API version used was too low:

    SKIPPED [1] tests/integration/api_service_test.py:882: API version is too low (< 1.38)
    SKIPPED [1] tests/integration/api_swarm_test.py:59: API version is too low (< 1.39)
    SKIPPED [1] tests/integration/api_swarm_test.py:38: API version is too low (< 1.39)
    SKIPPED [1] tests/integration/api_swarm_test.py:45: API version is too low (< 1.39)
    SKIPPED [1] tests/integration/api_swarm_test.py:52: API version is too low (< 1.39)

While it's possible to override the API version to use for testing
using the `DOCKER_TEST_API_VERSION` environment variable, we may want
to set the default to a version that supports all features that were
added.

This patch updates the default API version to v1.39, which is the minimum
version required for those features, and corresponds with Docker 18.09.

Note that the API version of the current (19.03) Docker release is v1.40,
but using that version as default would exclude users that did not update
their Docker version yet (and would not be needed yet for the features provided).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

* Makefile: set DOCKER_TEST_API_VERSION to v1.39

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-08-10 18:09:07 +02:00
docker Update default API version to v1.39 (#2512) 2020-08-10 18:09:07 +02:00
docs Spelling fixes (#2571) 2020-08-10 18:09:07 +02:00
scripts Merge branch 'release' into 4.0.0-release 2019-05-13 22:46:05 -07:00
tests Disable compression by default when using get_archive method 2020-08-10 18:09:07 +02:00
.coveragerc Add coverage 2014-07-11 16:13:00 +02:00
.dockerignore Makes docs builds faster and ensures proper ownership 2017-04-15 15:46:52 +02:00
.editorconfig Add EditorConfig to the repo. 2015-10-22 14:06:45 +00:00
.gitignore Add new Sphinx documentation 2016-11-22 17:05:43 +00:00
.readthedocs.yml Add readthedocs config 2019-05-18 19:54:35 -07:00
.travis.yml Implement context management, lifecycle and unittests. 2020-02-06 10:33:31 +01:00
CONTRIBUTING.md Rename non-URL occurrences of docker-py to "Docker SDK for Python" 2016-12-12 13:28:49 -08:00
Dockerfile Update to python 3.7 (buster) and use build-args 2019-10-03 15:49:26 +02:00
Dockerfile-docs Update to python 3.7 (buster) and use build-args 2019-10-03 15:49:26 +02:00
Dockerfile-py3 Update to python 3.7 (buster) and use build-args 2019-10-03 15:49:26 +02:00
Jenkinsfile Update test engine version to 19.03.12 2020-08-10 18:09:07 +02:00
LICENSE Fix licenses 2016-09-05 17:48:09 +02:00
MAINTAINERS Update MAINTAINERS file 2018-03-29 16:25:14 -07:00
MANIFEST.in Make dockerpycreds part of the SDK under docker.credentials 2019-04-30 23:37:55 -07:00
Makefile Update default API version to v1.39 (#2512) 2020-08-10 18:09:07 +02:00
README.md Require "requests[security]" if the `[tls]` option is selected, which also installs: 2017-08-17 13:38:40 -07:00
appveyor.yml Implement context management, lifecycle and unittests. 2020-02-06 10:33:31 +01:00
docs-requirements.txt Add new Sphinx documentation 2016-11-22 17:05:43 +00:00
pytest.ini pytest: update to v4.2.1 - use xunit2 for compatibility with Jenkins 2019-10-03 15:49:27 +02:00
requirements.txt Upgrade Windows dependency 2020-08-10 18:09:07 +02:00
setup.cfg Add License to PyPi metadata 2017-03-17 13:39:55 -04:00
setup.py Upgrade Windows dependency 2020-08-10 18:09:07 +02:00
test-requirements.txt Implement context management, lifecycle and unittests. 2020-02-06 10:33:31 +01:00
tox.ini Stop supporting EOL Python 3.4 2019-05-01 19:51:29 -07:00

README.md

Docker SDK for Python

Build Status

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. Either add docker to your requirements.txt file or install with pip:

pip install docker

If you are intending to connect to a docker host via TLS, add docker[tls] to your requirements instead, or install with pip:

pip install docker[tls]

Usage

Connect to Docker using the default socket or the configuration in your environment:

import docker
client = docker.from_env()

You can run containers:

>>> client.containers.run("ubuntu:latest", "echo hello world")
'hello world\n'

You can run containers in the background:

>>> client.containers.run("bfirsh/reticulate-splines", detach=True)
<Container '45e6d2de7c54'>

You can manage containers:

>>> 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:

>>> for line in container.logs(stream=True):
...   print line.strip()
Reticulating spline 2...
Reticulating spline 3...
...

You can manage images:

>>> client.images.pull('nginx')
<Image 'nginx'>

>>> client.images.list()
[<Image 'ubuntu'>, <Image 'nginx'>, ...]

Read the full documentation to see everything you can do.