A Python library for the Docker Engine API
Go to file
aiordache 0265818d10 release notes 4.4.4
Signed-off-by: aiordache <anca.iordache@docker.com>
2021-02-24 17:42:47 +01:00
.github Update GH action step 2021-02-10 10:35:55 -03:00
docker release notes 4.4.4 2021-02-24 17:42:47 +01:00
docs release notes 4.4.4 2021-02-24 17:42:47 +01:00
scripts
tests Fix SSH port parsing and add regression tests 2021-02-18 10:56:29 -03:00
.coveragerc
.dockerignore
.editorconfig
.gitignore
.readthedocs.yml
CONTRIBUTING.md
Dockerfile Shell out to SSH client for an ssh connection 2020-10-13 10:42:38 +02:00
Dockerfile-docs
Dockerfile-py3
Jenkinsfile Run unit tests in a container with no .docker/config mount 2021-02-11 19:58:35 +01:00
LICENSE
MAINTAINERS
MANIFEST.in
Makefile Shell out to SSH client for an ssh connection 2020-10-13 10:42:38 +02:00
README.md print() is a function in Python 3 2020-12-28 17:26:25 +00:00
appveyor.yml Implement context management, lifecycle and unittests. 2020-02-05 14:49:42 +01:00
docs-requirements.txt
pytest.ini pytest: update to v4.2.1 - use xunit2 for compatibility with Jenkins 2019-08-11 02:13:30 +02:00
requirements.txt Bump cffi to 1.14.4 2021-02-10 10:35:55 -03:00
setup.cfg
setup.py setup.py: Add support for Python 3.8 and 3.9 2020-12-24 15:14:05 +01:00
test-requirements.txt Implement context management, lifecycle and unittests. 2020-02-05 14:49:42 +01:00
tox.ini

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.