whatisgithub

What is docker-py?

docker/docker-py — explained in plain English

Analysis updated 2026-06-24

7,174PythonAudience · developerComplexity · 2/5Setup · moderate

In one sentence

The official Python library from Docker that lets you start, stop, and manage Docker containers and images entirely from Python code, replacing the need to run docker CLI commands in a shell.

Mindmap

mindmap
  root((docker-py))
    What it does
      Control Docker via Python
      Automate containers
    Operations
      Start and stop containers
      Pull images
      Fetch logs
      Manage Swarm
    Tech stack
      Python
      Docker Engine API
    Audience
      Python developers
      DevOps engineers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Automate spinning up and tearing down Docker containers from a Python test suite or CI pipeline script

USE CASE 2

Pull images, start containers, and retrieve logs programmatically inside a Python application

USE CASE 3

Manage Docker Swarm clusters and services from Python without shelling out to the docker CLI

What is it built with?

PythonDocker

How does it compare?

docker/docker-pylbryio/lbry-sdkmwouts/jupytext
Stars7,1747,1757,175
LanguagePythonPythonPython
Setup difficultymoderatehardeasy
Complexity2/54/52/5
Audiencedeveloperdeveloperdata

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · moderate Time to first run · 30min

Requires Docker Engine installed and running locally or a reachable remote Docker host.

The explanation does not mention the license type.

So what is it?

Docker SDK for Python is an official Python library that lets you control Docker from within a Python program. Docker is a tool for running applications inside containers, which are isolated, self-contained environments that include everything a program needs to run. Normally you interact with Docker through a command-line tool, but this library exposes the same capabilities through Python code, so you can automate Docker operations inside scripts or applications. With this library you can start and stop containers, list running containers, retrieve logs, pull container images from a registry, manage Docker Swarm clusters, and do most other things the docker command-line tool supports. You connect to the local Docker installation with a single call using the default socket, or configure it to connect to a remote Docker host. Installation is through pip, the standard Python package manager, with the package name docker. The README is short and focuses on quick examples: running a container and getting its output back as a string, starting a container in the background and retrieving a reference to it, listing running containers, fetching logs, stopping a container, and pulling or listing images. The full API documentation is hosted separately on Read the Docs. This is the official SDK maintained by Docker itself, so it tracks the Docker Engine API closely. It works with Docker containers, images, networks, volumes, and Swarm services.

Copy-paste prompts

Prompt 1
Using the Docker Python SDK, write a script that pulls the latest nginx image, starts a container on port 8080, waits 5 seconds, then prints the container logs.
Prompt 2
How do I use docker-py to list all currently running containers and stop any container whose name matches a given prefix?
Prompt 3
Write a Python function using docker-py that runs a shell command inside a new temporary container and returns the output as a string.
Prompt 4
Using the Docker Python SDK, how do I connect to a remote Docker host over TCP instead of the local Unix socket?

Frequently asked questions

What is docker-py?

The official Python library from Docker that lets you start, stop, and manage Docker containers and images entirely from Python code, replacing the need to run docker CLI commands in a shell.

What language is docker-py written in?

Mainly Python. The stack also includes Python, Docker.

What license does docker-py use?

The explanation does not mention the license type.

How hard is docker-py to set up?

Setup difficulty is rated moderate, with roughly 30min to a first successful run.

Who is docker-py for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.