Prefect integrations for working with Docker
Project description
prefect-docker
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
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file prefect-docker-0.2.3.tar.gz.
File metadata
- Download URL: prefect-docker-0.2.3.tar.gz
- Upload date:
- Size: 45.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86c1c4dabbb4f1cf11ced98989f2a0e5c96cd922f4b477b8b30542f7faefb686
|
|
| MD5 |
7879fb30c89d86dd26fbce6a4b63750e
|
|
| BLAKE2b-256 |
9ec9e92feb80505644a4a5d51743db4df3ba51beb6561b3a2478aa08602805c8
|
File details
Details for the file prefect_docker-0.2.3-py3-none-any.whl.
File metadata
- Download URL: prefect_docker-0.2.3-py3-none-any.whl
- Upload date:
- Size: 23.2 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 |
66c69ae611c05a764728afef09c8f3731bc92f68fcff72bcfb7938484035e6b7
|
|
| MD5 |
c75ed038b95a4778bbbb1970faf37683
|
|
| BLAKE2b-256 |
ddac1c182b4eb6547d21d893a21263f65326dfe73edab4c9b7d411171ebc0e44
|