Skip to main content

Use docker-compose (V2) from within Python

Project description

Docker Composer

A library to interact with docker-compose V2 from a python Program. All commands and parameters are exposed as python classes and attributes to allow for full auto-completion of its parameters with IDEs that support it.


pip install docker-composer


The main class is docker_composer.DockerCompose. Its parameters are all options from docker-compose.

Each docker-compose command has a corresponding function, e.g. or DockerCompose.scale. Their arguments again mirror the options of the corresponding command.

The resulting object has a call function. It takes arbitrary strings as input, as well as all keyword arguments from, and returns a subprocess.CompletedProcess

from docker_composer import DockerCompose

base = DockerCompose(file="docker-compose.yml", verbose=True), workdir="/tmp").call("app")"/tmp").call("app", "/bin/bash", "-l")

# /tmp $ ls /.dockerenv
# /.dockerenv
# /tmp $ exit

process =
#          Name                      Command           State    Ports
# -------------------------------------------------------------------
# myapp_app_70fd8b786b76   myapp --start-server        Exit 0        
# myapp_app_6ac3db4e1b55   myapp --client              Exit 0   


Coding Standards

Type Package Comment
Linter black Also for auto-formatted modules
Logging loguru
Packaging poetry
Tests pytest
Typing mypy Type all methods
Imports isort

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docker_composer-2.17.4.tar.gz (21.1 kB view hashes)

Uploaded source

Built Distribution

docker_composer-2.17.4-py3-none-any.whl (34.5 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page