DevOps & Cloud

docker

A remote control for Docker, so Python scripts can build and launch containers without touching the command line.

Install it: pip install docker

What does it do?

Docker lets you package an app plus everything it needs to run, like shipping a fully furnished apartment instead of just handing someone a blueprint. This Python library lets code talk directly to the Docker Engine, the same way you’d type commands into a terminal, but programmatically: start a container, stop one, check what’s running, pull a new image. It’s wiring a joystick into software that would otherwise require manual, one-at-a-time terminal commands. Automated testing systems and deployment tools use it to spin containers up and tear them down thousands of times a day.

See it in action

This starts a small demo container using Docker and prints out whatever message it produces.

import docker

client = docker.from_env()

container = client.containers.run("hello-world", detach=True)

print(container.logs().decode())

Why would a non-developer care?

Containers are why modern apps can be built on a laptop and then run identically on a massive server farm without the classic excuse of it working on one machine but not another. This library is what lets other software orchestrate that process automatically instead of a human clicking buttons.

Real-world examples

Large streaming and social platforms run enormous fleets of containers to serve their services, and behind many automated pipelines that build and test those containers, a library like this one is pulling the strings. Without it, every container action would require manually typing shell commands — fine for one container, a nightmare at the scale of thousands. It’s the difference between a chef cooking one meal by hand and a factory line told, in code, exactly what to prepare.

Who uses it

DevOps engineers and automation tools that need to programmatically manage containers as part of testing, deployment, or infrastructure pipelines.

How it compares to alternatives

It’s distinct from the kubernetes library, which manages fleets of containers across many machines — this one talks to a single Docker Engine directly. For simple start-and-stop tasks it’s the go-to; for orchestrating hundreds of containers across a cluster, people reach for kubernetes instead.

Fun fact

Docker takes its name and whale logo from shipping containers — the whole point of the technology is carrying your app as standardized cargo that fits on any ship, meaning any server.

New to Python and want to actually try libraries like this yourself?

Find a beginner-friendly course

Related libraries