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

Image constructor.

This class is DEPRECATED. Use the Environment class instead.

Image constructor is used to retrieve a cloud representation of a Image object associated with the provided workspace. Will return an instance of a child class corresponding to the specific type of the retrieved Image object.

Inheritance
ContainerImage

Constructor

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

Parameters

Name Description
workspace
Required

The workspace object containing the Image to retrieve

name
str

The name of the Image to retrieve. Will return the latest version, if it exists

Default value: None
id
str

The specific ID of the Image to retrieve. (ID is ":")

Default value: None
tags

Will filter Image results based on the provided list, by either 'key' or '[key, value]'. Ex. ['key', ['key2', 'key2 value']]

Default value: None
properties

Will filter Image results based on the provided list, by either 'key' or '[key, value]'. Ex. ['key', ['key2', 'key2 value']]

Default value: None
version
str

When version and name are both specified, will return the specific version of the Image.

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

Name Description
execution_script
Required
str

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
Required
str

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

conda_file
str

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

Default value: None
docker_file
str

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

Default value: None
schema_file
str

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

Default value: None
dependencies

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

Default value: None
enable_gpu

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

Default value: None
tags

Dictionary of key value tags to give this image.

Default value: None
properties

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

Default value: None
description
str

A text description to give this image.

Default value: None
base_image
str

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.

Default value: None
base_image_registry

Image registry that contains the base image.

Default value: None
cuda_version
str

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'.

Default value: None

Returns

Type Description

A configuration object to use when creating the image.

Exceptions

Type Description

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

Name Description
input_data
Required
<xref:varies>

The input data to pass to the image when run

Returns

Type Description
<xref:varies>

The results of running the image.

Exceptions

Type Description

serialize

Convert this ContainerImage object into a JSON serialized dictionary.

serialize()

Returns

Type Description

The JSON representation of this ContainerImage.

Exceptions

Type Description