Skip to main content

No project description provided

Project description

Dokker

Development

This is an open source project, and contributions are welcome! The api is only partially stable, so feel free to suggest changes or improvements.

Inspiration

This package is designed to manage docker compose projects programmatically via python.

It provides a simple way to create, start, stop, and remove docker compose projects, as well as a way to interact with the containers and services within the project ( like running commands,).

While other packages exist that provide similar functionality (e.g. python-on-whales, testcontainers, etc.), dokker focusses on interacting with the docker compose project asyncronously (using asyncio, but with sync apis).

This allows for patterns like inspecting the logs of a container while your python code is interacting with it.

The primary use case for this package is to create integration tests for docker compose projects. It easily integrates with pytest.

Installation

pip install dokker

Sync Usage

Imaging you have a docker-compose.yaml file that looks like this:

version: "3.4"

services:
  echo_service:
    image: hashicorp/http-echo
    command: ["-text", "Hello from HashiCorp!"]
    ports:
      - "5678:5678"

To utilize this project in python, you can use the local function to create a project from the docker-compose.yaml file. (you can also use other builder functions to create projects from other sources, e.g. a cookiecutter template)

from dokker import local, HealthCheck
import requests

# create a project from a docker-compose.yaml file
deployment = local(
    "docker-compose.yaml",
    health_checks=[
        HealthCheck(
            service="echo_service",
            url="http://localhost:5678",
            max_retries=2,
            timeout=5,
        )
    ],
)

watcher = deployment.logswatcher(
    "echo_service", wait_for_logs=True, 
)  # Creates a watcher for the echo_service service, a watcher
# will asynchronously collect the logs of the service and make them available

with deployment:
    # interact with the project

    deployment.up()  # start the project

    deployment.check_health()  # check the health of the project


    with watcher:

        # interact with the project
        print(requests.get("http://localhost:5678"))

        # as we set wait_for_logs=True, the watcher will block until the logs are collected

    print(watcher.collected_logs)
    # interact with the project

Async Usage

from dokker import local

# create a project from a docker-compose.yaml file
deployment = local("docker-compose.yaml")
deployment.up_on_enter = False # optional: do not start the project on enter

# start the project ()
async def main()
    async with deployment:
        # interact with the project
        await deployment.aup() # start the project (and detach)


        async with deployment.logwatcher("service_to_log", log=print):
            await deployment.arestart("service_to_log") # restart the service

        

asyncio.run(main())

Pytest Usage

import pytest
from dokker import local

@pytest.fixture(scope="session")
def deployment():
    deployment = local("docker-compose.yaml")
    deployment.health_on_enter = True
    with project:
        yield project

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

dokker-2.2.0.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dokker-2.2.0-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

File details

Details for the file dokker-2.2.0.tar.gz.

File metadata

  • Download URL: dokker-2.2.0.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.0

File hashes

Hashes for dokker-2.2.0.tar.gz
Algorithm Hash digest
SHA256 1cd37dbe7f8bdfe80e9d6f740e787d271a3dd8d7fba3326582152d0cebbf897f
MD5 ce90f14eb378f75a8c908fe8a3fd98a0
BLAKE2b-256 36fcf12579a6cb2b75f8ba7dd5c7b3f7c384c79607b1ec2ad1feeec209d52b14

See more details on using hashes here.

File details

Details for the file dokker-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: dokker-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 21.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.0

File hashes

Hashes for dokker-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 538e2576361d3b2162c334e19fd3977a0814f95479c09f710309b5f3aa9bd651
MD5 ce3a4e8fd1c98329f3307382e9f019f0
BLAKE2b-256 42852c03f6cd3ff59ed3cb214bc2442af246157eccfa0c7604dd79ac5c77a6db

See more details on using hashes here.

Supported by

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