skip to Main Content

As we know that to create a environment in Azure Machine Learning Workspace we need Conda dependencies file and base image. In my case you can see.

Build process using this conda file and base image will result into create of Image in Azure Container Registry whose url you can see here in portal.

I just want to know how to get Azure container registry url for this environment as azure portal is showing this information dashboard but when I am using Azure SKD for Python this is information is missing but all remaining information we are getting, even I have tried to print dict of Environment Object but no information is present. Any idea is appreciated.

Azure SDK for Python
Azure ML Workspace

Using this code you can print or get the information of particular environment.

environment = ml_client.environments.get(name=env_name, version="1")
print(environment)

But the information related to Azure Container Registry. I know that code is not implemented by Microsoft as I was going through source code of SDK.
If you have another way of implementation i just want that.

2

Answers


  1. Chosen as BEST ANSWER

    I was searching a lot around Azure SDK for Python v2 under Environment class but this object does contain any information about registered ACR image.

    Then I tried AzureML SDK under Environment class we can get the ACR image information and here is the code;

    from azureml.core import Workspace
    from azureml.core.environment import Environment
    from azureml.core.authentication import AzureCliAuthentication
    
    credential = AzureCliAuthentication()
    
    workspace = Workspace.get(
        name=workspace_name,
        subscription_id=subscription_id,
        resource_group=resource_group_name,
        auth=credential)
    
    environment = Environment.get(workspace=workspace, name="longformer", version="1")
    details = environment.get_image_details(workspace)
    container_repository = details["dockerImage"]["name"]
    print(container_repository)
    

    This will print you acr image for given environment name (for my case longformer) and environment version (for my case 1) and output will look like this:

    azureml/azureml_33d36abd731aa265b0dce682632fc38b
    

    Output


  2. Based on the documentation, the Azure ML Python SDK Environment properties does not provide a direct way to get the Azure Container Registry URL for the environment.

    However, one possible alternate can be with azure-containerregistry package.

    You can use this to list all the URLs for a particular container registry.

    import asyncio
    import os
    from azure.containerregistry.aio import ContainerRegistryClient
    from azure.identity.aio import DefaultAzureCredential
    
    # Create a new ContainerRegistryClient      
    audience = ""
    account_url = "<-URL->"
    credential = DefaultAzureCredential()
    client = ContainerRegistryClient(account_url, credential, audience=audience)
    async for repository_name in client.list_repository_names():
        print(repository_name)
    

    enter image description here

    enter image description here

    For more details you can check this documentation.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search