Skip to main content

Prefect integrations for interacting with Docker.

Project description

prefect-docker

PyPI

Welcome!

Prefect integrations for working with Docker.

Note! The DockerRegistryCredentials in prefect-docker is a unique block, separate from the DockerRegistry in prefect core. While DockerRegistry implements a few functionality from both DockerHost and DockerRegistryCredentials for convenience, it does not allow much configuration to interact with a Docker host.

Do not use DockerRegistry with this collection. Instead, use DockerHost and DockerRegistryCredentials.

Getting Started

Python setup

Requires an installation of Python 3.8+.

We recommend using a Python virtual environment manager such as pipenv, conda, or virtualenv.

These tasks are designed to work with Prefect 2. For more information about how to use Prefect, please refer to the Prefect documentation.

Installation

Install prefect-docker with pip:

pip install prefect-docker

Then, register to view the block on Prefect Cloud:

prefect block register -m prefect_docker

Note, to use the load method on Blocks, you must already have a block document saved through code or saved through the UI.

Pull image, and create, start, log, stop, and remove Docker container

from prefect import flow, get_run_logger
from prefect_docker.images import pull_docker_image
from prefect_docker.containers import (
    create_docker_container,
    start_docker_container,
    get_docker_container_logs,
    stop_docker_container,
    remove_docker_container,
)


@flow
def docker_flow():
    logger = get_run_logger()
    pull_docker_image("prefecthq/prefect", "latest")
    container = create_docker_container(
        image="prefecthq/prefect", command="echo 'hello world!' && sleep 60"
    )
    start_docker_container(container_id=container.id)
    logs = get_docker_container_logs(container_id=container.id)
    logger.info(logs)
    stop_docker_container(container_id=container.id)
    remove_docker_container(container_id=container.id)
    return container

Use a custom Docker Host to create a Docker container

from prefect import flow
from prefect_docker import DockerHost
from prefect_docker.containers import create_docker_container

@flow
def create_docker_container_flow():
    docker_host = DockerHost(
        base_url="tcp://127.0.0.1:1234",
        max_pool_size=4
    )
    container = create_docker_container(
        docker_host=docker_host,
        image="prefecthq/prefect",
        command="echo 'hello world!'"
    )

create_docker_container_flow()

Resources

If you encounter any bugs while using prefect-docker, feel free to open an issue in the prefect repository.

If you have any questions or issues while using prefect-docker, you can find help in the Prefect Slack community.

Development

If you'd like to install a version of prefect-docker for development, clone the repository and perform an editable install with pip:

git clone https://github.com/PrefectHQ/prefect-docker.git

cd prefect-docker/

pip install -e ".[dev]"

# Install linting pre-commit hooks
pre-commit install

Testing

The prefect-docker tests assume that you have a development image of Prefect available on the Docker daemon, and that it includes an installation of the same version of both Python and prefect that you are currently testing. You can build a compatible image from your source tree with:

prefect dev build-image

To run the tests, use the following command:

pytest

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

prefect_docker-0.5.4.tar.gz (35.2 kB view details)

Uploaded Source

Built Distribution

prefect_docker-0.5.4-py3-none-any.whl (24.8 kB view details)

Uploaded Python 3

File details

Details for the file prefect_docker-0.5.4.tar.gz.

File metadata

  • Download URL: prefect_docker-0.5.4.tar.gz
  • Upload date:
  • Size: 35.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for prefect_docker-0.5.4.tar.gz
Algorithm Hash digest
SHA256 7fdb27f4de16deccda3fbfaeda88670a25ccd8cb0ce6acc135ac41863abc4dae
MD5 7efae103d8eea2087115a484b598ffae
BLAKE2b-256 758788c727ed17820ba00d1090fcec7642b99ca20ece506c993e5ca524c626a1

See more details on using hashes here.

File details

Details for the file prefect_docker-0.5.4-py3-none-any.whl.

File metadata

File hashes

Hashes for prefect_docker-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3603b41bcf376b01f7bd0f1542d8a48b859138d6e73cf5470ff3478dd37b1136
MD5 822a79db5e59d27fa3b3b7a4d5953b4f
BLAKE2b-256 b93a6c54c071b2a3a52c1bc80ecdb111b7ccae53564efe12bb7aa2e5c8dfdc97

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