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.

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


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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file docker_composer-2.17.4.tar.gz.

File metadata

  • Download URL: docker_composer-2.17.4.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.9.15 Darwin/22.2.0

File hashes

Hashes for docker_composer-2.17.4.tar.gz
Algorithm Hash digest
SHA256 df54373892c320e88e576b470e22004cd2bd870fd0d315407e8b2afdb83c4ff4
MD5 e5addd0623e23a3b56de1eee31d7b4a9
BLAKE2b-256 2b761724b962aaa39aef82cce5f8803b1a442decf57349328cac70affd029900

See more details on using hashes here.

File details

Details for the file docker_composer-2.17.4-py3-none-any.whl.

File metadata

File hashes

Hashes for docker_composer-2.17.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ae52d971e0cdcd548c3d208085b47455530770f0f789d29dc5a4b296fe60c2a0
MD5 5cec0897a44c283abe48f2337930fa2e
BLAKE2b-256 85e68811c7d2b0b1f47696c9082c6dec3d5f97dbca1851ccb7db67b524da9c9e

See more details on using hashes here.

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