Skip to main content

Prefect integrations for working 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.7+.

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

These tasks are designed to work with Prefect 2.0. 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-docker repository.

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

Feel free to ⭐️ or watch prefect-docker for updates too!

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

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.2.1.tar.gz (44.2 kB view details)

Uploaded Source

Built Distribution

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

prefect_docker-0.2.1-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file prefect-docker-0.2.1.tar.gz.

File metadata

  • Download URL: prefect-docker-0.2.1.tar.gz
  • Upload date:
  • Size: 44.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for prefect-docker-0.2.1.tar.gz
Algorithm Hash digest
SHA256 de7587f34019a8c758225eb5cd9fe8b337b6f9008f52b5cdf0e715e1156867b0
MD5 b6289474cc42ef33f0dd26d449f0ce6f
BLAKE2b-256 8db6279795fa126d66fba53128723e272e4690cdb8c2ada1f483dc34d1d4e618

See more details on using hashes here.

File details

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

File metadata

  • Download URL: prefect_docker-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for prefect_docker-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7d6a6d1641b91e92fc3037a3e9f56ff464c86122f974b137b8981f6ebcba6daf
MD5 3c408d248ff7e9a6603083ec367552b5
BLAKE2b-256 41468d68a7938fb95c5323951de617694ec35353d23ef534ad3eff8b8f9acf99

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