python-on-whales

0.81.0 · active · verified Thu Apr 09

python-on-whales is an intuitive Python client for interacting with Docker, Docker Compose, and Docker Buildx, designed to be fun and intuitive. It simplifies running Docker commands from Python scripts, providing a fluent API. The library is currently at version 0.81.0 and releases updates frequently, often on a monthly or bi-monthly cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import the `docker` client and run a basic `hello-world` container. It verifies Docker is accessible and prints the container's output.

from python_on_whales import docker

# Ensure Docker client is running and accessible
try:
    print(f"Docker info: {docker.info().ServerVersion}")
    print("Running a simple 'hello-world' container...")
    # The output from 'hello-world' will be printed directly to stdout
    docker.run("hello-world")
    print("Hello-world container finished.")
except Exception as e:
    print(f"Error interacting with Docker: {e}")
    print("Please ensure Docker Desktop or the Docker CLI is installed and running.")

view raw JSON →