Use `docker compose` from within Python. This is a branch forked from https://github.com/schollm/docker-composer to support Docker Compose V2.
Project description
Docker Composer V2
A library to interact with docker compose
(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.
This project is based off the open source project: https://github.com/schollm/docker-composer The main goal for this branch-off effort is to make it work for the latest Docker Compose V2.
Install
pip install docker-composer-v2
Usage
The main class is docker_composer_v2.DockerCompose
. Its parameters are
all options from docker compose
.
Each docker compose
subcommand 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
import os
from docker_composer_v2 import DockerCompose
# set log level and verbose
os.environ["DOCKER_COMPOSE_LOG_LEVEL"] = "info"
# Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
base = DockerCompose(file="docker-compose.yml")
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(str(process.stdout, encoding="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
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
File details
Details for the file docker_composer_v2-0.8.8.tar.gz
.
File metadata
- Download URL: docker_composer_v2-0.8.8.tar.gz
- Upload date:
- Size: 21.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5735475e0248cb63410632b2c079e26fd9e0952f65347e08e0ba09439942db3f |
|
MD5 | 4f33ae6a898c77cc5120eff2aafdff70 |
|
BLAKE2b-256 | ebf117815094a6c2b379b3d470992ab7648db4a3c5a0f4c25f2f1dc412f3a0ee |
File details
Details for the file docker_composer_v2-0.8.8-py3-none-any.whl
.
File metadata
- Download URL: docker_composer_v2-0.8.8-py3-none-any.whl
- Upload date:
- Size: 35.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1d3a1c07c36b53ae28247cc886713468b89483116447579824deca3f93429c4 |
|
MD5 | 7d3ae64114077bb80c4506a649d1d496 |
|
BLAKE2b-256 | 84b592809eab879e3f98a69dbaebadae530a8d23fcebedb9739f00defb71e6e4 |