A Python library for the Docker Engine API
Go to file
Hakan Ardo c239d66d5d Verify TLS keys loaded from docker contexts
This maches the behaviour of the docker cli when using contexts.

Signed-off-by: Hakan Ardo <hakan@debian.org>
2021-03-03 09:30:19 +01:00
.github Update GH action step 2021-02-10 10:35:55 -03:00
docker Verify TLS keys loaded from docker contexts 2021-03-03 09:30:19 +01:00
docs Update changelog for 4.4.4 2021-02-24 18:20:24 +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
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
README.md print() is a function in Python 3 2020-12-28 17:26:25 +00:00
appveyor.yml
docs-requirements.txt
pytest.ini
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
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.