ContainerImage Class

Represents a container image, currently only for Docker images.

This class is DEPRECATED. Use the Environment class instead.

The image contains the dependencies needed to run the model including:

  • The runtime

  • Python environment definitions specified in a Conda file

  • Ability to enable GPU support

  • Custom Docker file for specific run commands

Inheritance
ContainerImage

Constructor

ContainerImage(workspace, name=None, id=None, tags=None, properties=None, version=None)

Parameters

workspace
name
default value: None
id
default value: None
tags
default value: None
properties
default value: None
version
default value: None

Remarks

A ContainerImage is retrieved using the Image class constructor by passing the name or id of a previously created ContainerImage. The following code example shows an Image retrieval from a Workspace by both name and id.


   container_image_from_name = Image(workspace, name="image-name")
   container_image_from_id = Image(workspace, id="image-id")

To create a new Image configuration to use in a deployment, build a ContainerImageConfig object as shown in the following code example:


   from azureml.core.image import ContainerImage

   image_config = ContainerImage.image_configuration(execution_script="score.py",
                                                    runtime="python",
                                                    conda_file="myenv.yml",
                                                    description="image for model",
                                                    cuda_version="9.0"
                                                    )

Methods

image_configuration

Create and return a ContainerImageConfig object.

This function accepts parameters to define how your model should run within the Webservice, as well as the specific environment and dependencies it needs to be able to run.

run

Run the image locally with the given input data.

Must have Docker installed and running to work. This method will only work on CPU, as the GPU-enabled image can only run on Microsoft Azure Services.

serialize

Convert this ContainerImage object into a JSON serialized dictionary.

image_configuration

Create and return a ContainerImageConfig object.

This function accepts parameters to define how your model should run within the Webservice, as well as the specific environment and dependencies it needs to be able to run.

static image_configuration(execution_script, runtime, conda_file=None, docker_file=None, schema_file=None, dependencies=None, enable_gpu=None, tags=None, properties=None, description=None, base_image=None, base_image_registry=None, cuda_version=None)

Parameters

execution_script
str
Required

Path to local Python file that contains the code to run for the image. Must include both init() and run(input_data) functions that define the model execution steps for the Webservice.

runtime
str
Required

The runtime to use for the image. Current supported runtimes are 'spark-py' and 'python'.

conda_file
str
default value: None

Path to local .yml file containing a Conda environment definition to use for the image.

docker_file
str
default value: None

Path to local file containing additional Docker steps to run when setting up the image.

schema_file
str
default value: None

Path to local file containing a webservice schema to use when the image is deployed. Used for generating Swagger specs for a model deployment.

dependencies
list[str]
default value: None

List of paths to additional files/folders that the image needs to run.

enable_gpu
bool
default value: None

Whether or not to enable GPU support in the image. The GPU image must be used on Microsoft Azure Services such as Azure Container Instances, Azure Machine Learning Compute, Azure Virtual Machines, and Azure Kubernetes Service. Defaults to False

tags
dict[str, str]
default value: None

Dictionary of key value tags to give this image.

properties
dict[str, str]
default value: None

Dictionary of key value properties to give this image. These properties cannot be changed after deployment, however new key value pairs can be added.

description
str
default value: None

A text description to give this image.

base_image
str
default value: None

A custom image to be used as base image. If no base image is given then the base image will be used based off of given runtime parameter.

base_image_registry
ContainerRegistry
default value: None

Image registry that contains the base image.

cuda_version
str
default value: None

Version of CUDA to install for images that need GPU support. The GPU image must be used on Microsoft Azure Services such as Azure Container Instances, Azure Machine Learning Compute, Azure Virtual Machines, and Azure Kubernetes Service. Supported versions are 9.0, 9.1, and 10.0. If 'enable_gpu' is set, this defaults to '9.1'.

Returns

A configuration object to use when creating the image.

Return type

Exceptions

run

Run the image locally with the given input data.

Must have Docker installed and running to work. This method will only work on CPU, as the GPU-enabled image can only run on Microsoft Azure Services.

run(input_data)

Parameters

input_data
<xref:varies>
Required

The input data to pass to the image when run

Returns

The results of running the image.

Return type

<xref:varies>

Exceptions

serialize

Convert this ContainerImage object into a JSON serialized dictionary.

serialize()

Returns

The JSON representation of this ContainerImage.

Return type

Exceptions