prefect_docker.worker
Module containing the Docker worker used for executing flow runs as Docker containers.
To start a Docker worker, run the following command:
my-work-pool with the name of the work pool you want the worker
to poll for flow runs.
For more information about work pools and workers,
checkout out the Prefect docs.
Classes
ImagePullPolicy
Enum representing the image pull policy options for a Docker container.
DockerWorkerJobConfiguration
Configuration class used by the Docker worker.
An instance of this class is passed to the Docker worker’s run method
for each flow run. It contains all the information necessary to execute the
flow run as a Docker container.
Attributes:
name: The name to give to created Docker containers.command: The command executed in created Docker containers to kick off flow run execution.env: The environment variables to set in created Docker containers.labels: The labels to set on created Docker containers.image: The image reference of a container image to use for created jobs. If not set, the latest Prefect image will be used.image_pull_policy: The image pull policy to use when pulling images.networks: Docker networks that created containers should be connected to.network_mode: The network mode for the created containers (e.g. host, bridge). If ‘networks’ is set, this cannot be set.auto_remove: If set, containers will be deleted on completion.volumes: Docker volumes that should be mounted in created containers.stream_output: If set, the output from created containers will be streamed to local standard output.mem_limit: Memory limit of created containers. Accepts a value with a unit identifier (e.g. 100000b, 1000k, 128m, 1g.) If a value is given without a unit, bytes are assumed.memswap_limit: Total memory (memory + swap), -1 to disable swap. Should only be set ifmem_limitis also set. Ifmem_limitis set, this defaults to allowing the container to use as much swap as memory. For example, ifmem_limitis 300m andmemswap_limitis not set, containers can use 600m in total of memory and swap.privileged: Give extended privileges to created containers.container_create_kwargs: Extra args for docker py when creating container.
get_extra_hosts
get_network_mode
prepare_for_flow_run
DockerWorkerResult
Contains information about a completed Docker container
DockerWorker
Prefect worker that executes flow runs within Docker containers.
Methods:
kill_infrastructure
infrastructure_pid: The infrastructure identifier in format “docker_host_base_url:container_id”.configuration: The job configuration (not used for Docker but kept for API compatibility).grace_seconds: Time to allow for graceful shutdown before force killing.
InfrastructureNotFound: If the container doesn’t exist.