AzureContainerInstancesOperator

Microsoft AzureCertified

Start a container on Azure Container Instances

View Source

Last Updated: May. 7, 2021

Access Instructions

Install the Microsoft Azure provider package into your Airflow environment.

Import the module into your DAG file and instantiate it with your desired params.

Parameters

ci_conn_idstrconnection id of a service principal which will be used to start the container instance
registry_conn_idOptional[str]connection id of a user which can login to a private docker registry. If None, we assume a public registry
resource_groupstrname of the resource group wherein this container instance should be started
namestrname of this container instance. Please note this name has to be unique in order to run containers in parallel.
imagestrthe docker image to be used
regionstrthe region wherein this container instance should be started
environment_variablesOptional[dict]key,value pairs containing environment variables which will be passed to the running container
secured_variablesOptional[str]names of environmental variables that should not be exposed outside the container (typically passwords).
volumeslist[<conn_id, account_name, share_name, mount_path, read_only>]list of Volume tuples to be mounted to the container. Currently only Azure Fileshares are supported.
memory_in_gbdoublethe amount of memory to allocate to this container
cpudoublethe number of cpus to allocate to this container
gpuazure.mgmt.containerinstance.models.GpuResourceGPU Resource for the container.
commandOptional[List[str]]the command to run inside the container
container_timeoutdatetime.timedeltamax time allowed for the execution of the container instance.
tagsOptional[dict[str, str]]azure tags as dict of str:str
os_typestrThe operating system type required by the containers in the container group. Possible values include: 'Windows', 'Linux'
restart_policystrRestart policy for all containers within the container group. Possible values include: 'Always', 'OnFailure', 'Never'
ip_addressIpAddressThe IP address type of the container group.

Documentation

Start a container on Azure Container Instances

Example:

AzureContainerInstancesOperator(
ci_conn_id = "azure_service_principal",
registry_conn_id = "azure_registry_user",
resource_group = "my-resource-group",
name = "my-container-name-{{ ds }}",
image = "myprivateregistry.azurecr.io/my_container:latest",
region = "westeurope",
environment_variables = {"MODEL_PATH": "my_value",
"POSTGRES_LOGIN": "{{ macros.connection('postgres_default').login }}",
"POSTGRES_PASSWORD": "{{ macros.connection('postgres_default').password }}",
"JOB_GUID": "{{ ti.xcom_pull(task_ids='task1', key='guid') }}" },
secured_variables = ['POSTGRES_PASSWORD'],
volumes = [("azure_wasb_conn_id",
"my_storage_container",
"my_fileshare",
"/input-data",
True),],
memory_in_gb=14.0,
cpu=4.0,
gpu=GpuResource(count=1, sku='K80'),
command=["/bin/echo", "world"],
task_id="start_container"
)

Was this page helpful?