A Python library for the Docker Engine API.
Project Links
Meta
Maintainer: Docker Inc.
Requires Python: >=3.8
Classifiers
Development Status
- 5 - Production/Stable
Environment
- Other Environment
Intended Audience
- Developers
License
- OSI Approved :: Apache Software License
Operating System
- OS Independent
Programming Language
- Python
- Python :: 3
- Python :: 3.8
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
Topic
- Software Development
- Utilities
Docker SDK for Python
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. 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:
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.
May 23, 2024
7.1.0
Dec 08, 2023
7.0.0
Dec 05, 2023
7.0.0b3
Nov 27, 2023
7.0.0b2
Jun 01, 2023
6.1.3
May 11, 2023
6.1.2
May 07, 2023
6.1.1
May 05, 2023
6.1.0
Nov 02, 2022
6.0.1
Aug 18, 2022
6.0.0
Aug 11, 2022
6.0.0b2
Jul 30, 2022
6.0.0b1
Oct 07, 2021
5.0.3
Sep 01, 2021
5.0.2
Aug 31, 2021
5.0.1
Apr 06, 2021
5.0.0
Feb 24, 2021
4.4.4
Feb 18, 2021
4.4.3
Feb 15, 2021
4.4.2
Dec 22, 2020
4.4.1
Nov 23, 2020
4.4.0
Aug 21, 2020
4.3.1
Aug 10, 2020
4.3.0
Jun 30, 2020
4.2.2
Jun 02, 2020
4.2.1
Feb 06, 2020
4.2.0
Oct 03, 2019
4.1.0
Jun 20, 2019
4.0.2
May 19, 2019
4.0.1
May 19, 2019
4.0.0
Jun 21, 2019
3.7.3
Mar 28, 2019
3.7.2
Mar 20, 2019
3.7.1
Jan 10, 2019
3.7.0
Nov 28, 2018
3.6.0
Oct 17, 2018
3.5.1
Aug 10, 2018
3.5.0
Jun 29, 2018
3.4.1
Jun 18, 2018
3.4.0
Apr 26, 2018
3.3.0
Mar 30, 2018
3.2.1
Mar 29, 2018
3.2.0
Mar 21, 2018
3.1.4
Mar 20, 2018
3.1.3
Mar 20, 2018
3.1.2
Mar 05, 2018
3.1.1
Feb 22, 2018
3.1.0
Feb 05, 2018
3.0.1
Feb 01, 2018
3.0.0
Dec 19, 2017
2.7.0
Nov 09, 2017
2.6.1
Nov 07, 2017
2.6.0
Aug 23, 2017
2.5.1
Aug 17, 2017
2.5.0
Jun 28, 2017
2.4.2
Jun 28, 2017
2.4.1
Jun 28, 2017
2.4.0
May 17, 2017
2.3.0
Mar 28, 2017
2.2.1
Mar 21, 2017
2.2.0
Feb 17, 2017
2.1.0
Jan 20, 2017
2.0.2
Jan 09, 2017
2.0.1
Dec 12, 2016
2.0.0