Search code examples
azure-machine-learning-service

How to update the existing web service with a new docker image on Azure Machine Learning Services?


I am currently working on machine learning project with Azure Machine Learning Services. But I found the problem that I can't update a new docker image to the existing web service (I want to same url as running we service).

I have read the documentation but it doesn't really tell me how to update (documentation link: https://learn.microsoft.com/en-us/azure/machine-learning/service/how-to-deploy-and-where). The documentation said that we have to use update() with image = new-image.

from azureml.core.webservice import Webservice

service_name = 'aci-mnist-3

# Retrieve existing service
service = Webservice(name = service_name, workspace = ws)

# Update the image used by the service
service.update(image = new-image)

print(service.state)

But the new-image isn't described where it comes from.

Does anyone know how to figure out this problem?

Thank you


Solution

  • The documentation could be a little more clear on this part, I agree. The new-image is an image object that you should pass into the update() function. If you just created the image you might already have the object in a variable, then just pass it. If not, then you can obtain it from your workspace using

    from azureml.core.image.image import Image
    new_image = Image(ws, image_name)
    

    where ws is your workspace object and image_name is a string with the name of the image you want to obtain. Then you go on calling update() as

    from azureml.core.webservice import Webservice
    
    service_name = 'aci-mnist-3'
    
    # Retrieve existing service
    service = Webservice(name = service_name, workspace = ws)
    
    # Update the image used by the service
    service.update(image = new_image) # Note that dash isn't supported in variable names
    
    print(service.state)
    

    You can find more information in the SDK documentation

    EDIT: Both the Image and the Webservice classes above are abstract parent classes.

    For the Image object, you should really use one of these classes, depending on your case:

    • ContainerImage
    • UnknownImage

    (see Image package in the documentation).

    For the Webservice object, you should use one of these classes, depending on your case:

    • AciWebservice
    • AksWebservice
    • UnknownWebservice

    (see Webservice package in the documentation).