Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/docker/docker-py
A Python library for the Docker Engine API
https://github.com/docker/docker-py
docker docker-engine-api docker-swarm python python-library
Last synced: 5 days ago
JSON representation
A Python library for the Docker Engine API
- Host: GitHub
- URL: https://github.com/docker/docker-py
- Owner: docker
- License: apache-2.0
- Created: 2013-05-23T16:15:07.000Z (over 11 years ago)
- Default Branch: main
- Last Pushed: 2024-11-18T17:03:12.000Z (about 2 months ago)
- Last Synced: 2025-01-04T08:39:40.962Z (7 days ago)
- Topics: docker, docker-engine-api, docker-swarm, python, python-library
- Language: Python
- Homepage: https://docker-py.readthedocs.io/
- Size: 4.9 MB
- Stars: 6,872
- Watchers: 193
- Forks: 1,674
- Open Issues: 495
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-projects - docker-py - An API client for docker written in Python (Python)
- awesome-robotic-tooling - docker-py - A Python library for the Docker Engine API (Interaction / High Performance Computing)
- awesome-list - Docker SDK for Python - A Python library for the Docker Engine API (DevOps / Data Management)
- awesome-list-docker - docker-py
- starred-awesome - docker-py - A Python library for the Docker Engine API (Python)
- best-of-python - GitHub - 27% open · ⏱️ 23.05.2024): (Infrastructure & DevOps)
- awesomeLibrary - docker-py - A Python library for the Docker Engine API (语言资源库 / python)
README
# Docker SDK for Python
[![Build Status](https://github.com/docker/docker-py/actions/workflows/ci.yml/badge.svg)](https://github.com/docker/docker-py/actions/workflows/ci.yml)
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](https://pypi.python.org/pypi/docker/). 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:
```python
import docker
client = docker.from_env()
```You can run containers:
```python
>>> client.containers.run("ubuntu:latest", "echo hello world")
'hello world\n'
```You can run containers in the background:
```python
>>> client.containers.run("bfirsh/reticulate-splines", detach=True)```
You can manage containers:
```python
>>> client.containers.list()
[, , ...]>>> container = client.containers.get('45e6d2de7c54')
>>> container.attrs['Config']['Image']
"bfirsh/reticulate-splines">>> container.logs()
"Reticulating spline 1...\n">>> container.stop()
```You can stream logs:
```python
>>> for line in container.logs(stream=True):
... print(line.strip())
Reticulating spline 2...
Reticulating spline 3...
...
```You can manage images:
```python
>>> client.images.pull('nginx')>>> client.images.list()
[, , ...]
```[Read the full documentation](https://docker-py.readthedocs.io) to see everything you can do.