Use docker-compose from within Python
Project description
Docker Composer
A library to interact with docker-compose
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.
Install
pip install docker-composer
Usage
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.
DockerCompose.run
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
subprocess.run
, and returns a subprocess.CompletedProcess
from docker_composer import DockerCompose
base = DockerCompose(file="docker-compose.yml", verbose=True)
base.run(detach=True, workdir="/tmp").call("app")
base.run(workdir="/tmp").call("app", "/bin/bash", "-l")
# /tmp $ ls /.dockerenv
# /.dockerenv
# /tmp $ exit
process = base.ps(all=True).call(capture_output=True)
print(process.stdout.encode("UTF-8"))
# Name Command State Ports
# -------------------------------------------------------------------
# myapp_app_70fd8b786b76 myapp --start-server Exit 0
# myapp_app_6ac3db4e1b55 myapp --client Exit 0
Develop
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for docker_composer-2.17.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d728acabe5a84393b08ffafe1de5acab4cdf1eee088c8c8d53748e76610b9a8 |
|
MD5 | e448e70051dd47090baca0060c963e03 |
|
BLAKE2b-256 | 5a7c78652f75363e1491e7d927652e5891f604feb7eb6e7c0ce3b199872d5ab4 |