Search code examples
pythonpython-3.xazuredockerazure-machine-learning-service

Deploy Azure Machine Learning models using Custom Docker Image on Azure Container Regisrty


I want to train Azure Machine Learning model on azure using Azure Machine Learning Service. But I want to use the custom Docker image for deploying the model on azure. I am not able to understand how to deploy Machine Learning models using Custom Docker Image.

Please share me if there is any tutorial or blog about the deploy ml models using a custom image.

Please check the below Docker file commands:-

# Set locale
RUN apt-get update
RUN apt-get install locales
RUN locale-gen en_US.UTF-8
RUN update-locale LANG=en_US.UTF-8

# Install MS SQL v13 driver for PyOdbc
RUN apt-get install -y curl
RUN apt-get install apt-transport-https
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - 
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN exit
RUN apt-get update

RUN ACCEPT_EULA=Y apt-get install -y msodbcsql
RUN apt-get install -y unixodbc-dev

I want to use the Azure Container Registry for push the docker image and use the Custom Docker Image. Please let me know if there is any way.

Is there any way to Deploy Azure ML Models using Custom docker images?


Solution

  • You can do following:

    1. Create an [Environment][1] with the coordinates of your custom Docker image specified in Docker section.
    2. Create [InferenceConfig][2] with that Environment as argument, and use it when deploying the model.

    For example, assuming you have a model already and eliding other arguments:

    from azureml.core.environment import Environment
    from azureml.core.model import InferenceConfig
    
    env = Environment(name="myenv")
    env.docker.base_image = "mybaseimage"
    env.docker.base_image_registry.address = "ip-address"
    env.docker.base_image_registry.username = "my-username"
    env.docker.base_image_registry.password = "my-password"
    
    ic = InferenceConfig(…,environment = env)
    model.deploy(…,inference_config = ic)
    
    
      [1]: https://learn.microsoft.com/en-us/python/api/azureml-core/azureml.core.environment.environment?view=azure-ml-py
      [2]: https://learn.microsoft.com/en-us/python/api/azureml-core/azureml.core.model.inferenceconfig?view=azure-ml-py