Edit

Share via


Deploy a model to Azure Container Instances with CLI (v1)

Important

Some of the Azure CLI commands in this article use the azure-cli-ml, or v1, extension for Azure Machine Learning. Support for CLI v1 ended on September 30, 2025. Microsoft will no longer provide technical support or updates for this service. Your existing workflows using CLI v1 will continue to operate after the end-of-support date. However, they could be exposed to security risks or breaking changes in the event of architectural changes in the product.

We recommend that you transition to the ml, or v2, extension as soon as possible. For more information on the v2 extension, see Azure Machine Learning CLI extension and Python SDK v2.

Important

This article provides information on using the Azure Machine Learning SDK v1. SDK v1 is deprecated as of March 31, 2025. Support for it will end on June 30, 2026. You can install and use SDK v1 until that date. Your existing workflows using SDK v1 will continue to operate after the end-of-support date. However, they could be exposed to security risks or breaking changes in the event of architectural changes in the product.

We recommend that you transition to the SDK v2 before June 30, 2026. For more information on SDK v2, see What is Azure Machine Learning CLI and Python SDK v2? and the SDK v2 reference.

Important

This article shows how to use the CLI and SDK v1 to deploy a model. For the recommended approach for v2, see Deploy and score a machine learning model by using an online endpoint.

Learn how to use Azure Machine Learning to deploy a model as a web service on Azure Container Instances (ACI). Use Azure Container Instances if you:

  • prefer not to manage your own Kubernetes cluster
  • are okay with having only a single replica of your service, which might affect uptime

For information on quota and region availability for ACI, see the Quotas and region availability for Azure Container Instances article.

Important

Debug locally before deploying to the web service. For more information, see Debug Locally.

You can also refer to Azure Machine Learning - Deploy to Local Notebook.

Prerequisites

Limitations

Note

  • Deploying Azure Container Instances in a virtual network isn't supported. Instead, for network isolation, consider using managed online endpoints.
  • To ensure effective support, you must supply the necessary logs for your ACI containers. Without these logs, technical support can't be guaranteed. Use log analytics tools by specifying enable_app_insights=True in your deployment configuration to manage and analyze your ACI container logs efficiently.

Deploy to ACI

To deploy a model to Azure Container Instances, create a deployment configuration that describes the compute resources needed, such as the number of cores and memory. You also need an inference configuration, which describes the environment needed to host the model and web service. For more information on creating the inference configuration, see How and where to deploy models.

Note

  • ACI is suitable only for small models that are under 1 GB in size.
  • Use single-node AKS to dev-test larger models.
  • You can deploy up to 1,000 models per deployment (per container).

Using the SDK

APPLIES TO: Azure Machine Learning SDK v1 for Python

from azureml.core.webservice import AciWebservice, Webservice
from azureml.core.model import Model

deployment_config = AciWebservice.deploy_configuration(cpu_cores = 1, memory_gb = 1)
service = Model.deploy(ws, "aciservice", [model], inference_config, deployment_config)
service.wait_for_deployment(show_output = True)
print(service.state)

For more information on the classes, methods, and parameters used in this example, see the following reference articles:

Using the Azure CLI

APPLIES TO: Azure CLI ml extension v1

To deploy by using the CLI, run the following command. Replace mymodel:1 with the name and version of the registered model. Replace myservice with the name to give this service:

az ml model deploy -n myservice -m mymodel:1 --ic inferenceconfig.json --dc deploymentconfig.json

The entries in the deploymentconfig.json file map to the parameters for AciWebservice.deploy_configuration. The following table describes the mapping between the entities in the JSON file and the parameters for the method:

JSON entity Method parameter Description
computeType NA The compute target. For ACI, the value must be ACI.
containerResourceRequirements NA Container for the CPU and memory entities.
  cpu cpu_cores The number of CPU cores to allocate. Default, 0.1
  memoryInGB memory_gb The amount of memory (in GB) to allocate for this web service. Default, 0.5
location location The Azure region to deploy this web service to. If you don't specify this value, the workspace location is used. For more details on available regions, see ACI Regions.
authEnabled auth_enabled Whether to enable auth for this web service. Defaults to False
sslEnabled ssl_enabled Whether to enable TLS for this web service. Defaults to False.
appInsightsEnabled enable_app_insights Whether to enable AppInsights for this web service. Defaults to False
sslCertificate ssl_cert_pem_file The cert file needed if TLS is enabled
sslKey ssl_key_pem_file The key file needed if TLS is enabled
cname ssl_cname The CNAME for if TLS is enabled
dnsNameLabel dns_name_label The DNS name label for the scoring endpoint. If you don't specify this value, a unique DNS name label is generated for the scoring endpoint.

The following JSON is an example deployment configuration for use with the CLI:

{
    "computeType": "aci",
    "containerResourceRequirements":
    {
        "cpu": 0.5,
        "memoryInGB": 1.0
    },
    "authEnabled": true,
    "sslEnabled": false,
    "appInsightsEnabled": false
}

For more information, see the az ml model deploy reference.

Using VS Code

See how to manage resources in VS Code.

Important

You don't need to create an ACI container to test in advance. The solution creates ACI containers as needed.

Important

The solution appends a hashed workspace ID to all underlying ACI resources that it creates. All ACI names from the same workspace have the same suffix. The Azure Machine Learning service name stays the same as the customer-provided service_name. The Azure Machine Learning SDK APIs that users see don't need any change. The solution doesn't give any guarantees on the names of underlying resources that it creates.

Next steps