ContainerTask
This is an intermediate class that represents Flyte Tasks that run a container at execution time. This is the vast majority of tasks - the typical @task decorated tasks; for instance, all run a container. An example of something that doesn't run a container would be something like the Athena SQL task.
Attributes
| Attribute | Type | Description |
|---|---|---|
| MetadataFormat | typing.Literal = Literal["JSON", "YAML", "PROTO"] | The format of the output file, which can be "JSON", "YAML", or "PROTO". |
Constructor
Signature
def ContainerTask(
self,
name: str,
image: Union[str, Image],
command: List[str],
inputs: Optional[Dict[str, Type]] = None,
arguments: Optional[List[str]] = None,
outputs: Optional[Dict[str, Type]] = None,
input_data_dir: str | pathlib.Path = "/var/inputs",
output_data_dir: str | pathlib.Path = "/var/outputs",
metadata_format: MetadataFormat = "JSON",
local_logs: bool = True,
block_network: bool = False,
**kwargs,
): ...
Parameters
| Name | Type | Description |
|---|---|---|
| name | str | Name of the task. |
| image | Union[str, [Image](../../image/image.md?sid=flyte__image_image)] | The container image to use for the task. This can be a string or an Image object. |
| command | List[str] | The command to run in the container. This can be a list of strings or a single string. |
| inputs | Optional[Dict[str, Type]] = None | The inputs to the task. This is a dictionary of input names to types. |
| arguments | Optional[List[str]] = None | The arguments to pass to the command. This is a list of strings. |
| outputs | Optional[Dict[str, Type]] = None | The outputs of the task. This is a dictionary of output names to types. |
| input_data_dir | `str | pathlib.Path` = "/var/inputs" |
| output_data_dir | `str | pathlib.Path` = "/var/outputs" |
| metadata_format | MetadataFormat = "JSON" | The format of the output file. This can be "JSON", "YAML", or "PROTO". |
| local_logs | bool = True | If True, logs will be printed to the console in the local execution. |
| block_network | bool = False | If True, blocks all outbound network access. Locally this sets Docker network_mode=none. On-cluster it applies the pod template sandboxed-pod-template. Defaults to False. |
| kwargs | Any | Additional keyword arguments passed to the superclass TaskTemplate initializer. |
Methods
execute()
async def execute(self, **kwargs) -> Any: ...
Executes the container task locally using Docker, setting up volume bindings, streaming logs, and returning parsed output values.
Parameters
| Name | Type | Description |
|---|---|---|
| kwargs | Any | Task inputs passed to the container command template and volume mounts |
Returns
| Type | Description |
|---|---|
Any | The task execution outputs parsed into their expected types |
data_loading_config()
def data_loading_config(self, sctx: SerializationContext) -> tasks_pb2.DataLoadingConfig: ...
Constructs the Flyte DataLoadingConfig protobuf message specifying container input/output directories and data format.
Parameters
| Name | Type | Description |
|---|---|---|
| sctx | SerializationContext | The serialization context used during task compilation |
Returns
| Type | Description |
|---|---|
tasks_pb2.DataLoadingConfig | The protobuf message configuring data loading behavior for Flyte engine execution |
container_args()
def container_args(self, sctx: SerializationContext) -> List[str]: ...
Builds the full sequence of command and argument strings to pass to the container entrypoint.
Parameters
| Name | Type | Description |
|---|---|---|
| sctx | SerializationContext | The serialization context used during task compilation |
Returns
| Type | Description |
|---|---|
List[str] | A list of strings representing the combined container command and arguments |