You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
Stefan Scherer a48a5a9647
Merge pull request #2898 from hugovk/add-3.10
9 months ago
.github Add support for Python 3.10 9 months ago
docker Merge pull request #2806 from feliperuhland/fix-low-level-volumes-example 9 months ago
docs Post-release changelog update 9 months ago
scripts use python3.6+ constructs 1 year ago
tests Don't install mock backport 9 months ago
.coveragerc Add coverage 8 years ago
.dockerignore Makes docs builds faster and ensures proper ownership 5 years ago
.editorconfig Add EditorConfig to the repo. 7 years ago
.gitignore Add new Sphinx documentation 6 years ago
.readthedocs.yml Remove support to pre python 3.6 1 year ago
CONTRIBUTING.md Rename non-URL occurrences of docker-py to "Docker SDK for Python" 6 years ago
Dockerfile Remove support to pre python 3.6 1 year ago
Dockerfile-docs Update to python 3.7 (buster) and use build-args 3 years ago
Jenkinsfile Remove support to pre python 3.6 1 year ago
LICENSE Fix licenses 6 years ago
MAINTAINERS Update maintainers 1 year ago
MANIFEST.in Make dockerpycreds part of the SDK under docker.credentials 3 years ago
Makefile Update API and Engine versions 1 year ago
README.md Fix continuous integration status badged 1 year ago
appveyor.yml Implement context management, lifecycle and unittests. 2 years ago
docs-requirements.txt Add new Sphinx documentation 6 years ago
pytest.ini pytest: update to v4.2.1 - use xunit2 for compatibility with Jenkins 3 years ago
requirements.txt Bump minimum paramiko to support Python 3.10 9 months ago
setup.cfg Universal wheels are for code expected to work on both Python 2 and 3 9 months ago
setup.py Bump minimum paramiko to support Python 3.10 9 months ago
test-requirements.txt Don't install mock backport 9 months ago
tox.ini Remove support to pre python 3.6 1 year ago

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.