@@ -539,6 +539,120 @@ wps_connection = WorkspaceConnection(
539
539
ml_client.connections.create_or_update(workspace_connection = wps_connection)
540
540
```
541
541
542
+ ---
543
+
544
+ ### Third party Container Registry
545
+
546
+ Using the GenericContainerRegistry workspace connection, you can specify an external registry for image builds. Environment images will be pushed and served from the specified registry, and the previous cache will be ignored.
547
+
548
+ # [ Azure CLI] ( #tab/cli )
549
+
550
+ Create a connection using the following YAML files. Be sure to update the appropriate values:
551
+ ``` yml
552
+ # myenv.yml
553
+ $schema : https://azuremlschemas.azureedge.net/latest/environment.schema.json
554
+ name : docker-image-plus-conda-example
555
+ image : mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu20.04
556
+ type : python_feed
557
+ conda_file : conda_dep.yml
558
+ description : Environment created from a Docker image plus Conda environment
559
+ ` ` `
560
+
561
+ ` ` ` yml
562
+ # conda_dep.yml
563
+ name : project_environment
564
+ dependencies :
565
+ - python=3.10
566
+ - pip :
567
+ - azureml-defaults
568
+ channels :
569
+ - anaconda
570
+ - conda-forge
571
+ ` ` `
572
+
573
+ ` ` ` yml
574
+ # connection.yml
575
+ name : ws_conn_generic_container_registry
576
+ type : container_registry
577
+ target : https://test-registry.com
578
+ credentials :
579
+ type : username_password
580
+ username : contoso
581
+ password : pass
582
+ ` ` `
583
+
584
+ ` ` ` yml
585
+ # hello_world_job.yml
586
+ $schema : https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
587
+ command : echo "hello world"
588
+ environment : azureml:<env name>@latest
589
+ ` ` `
590
+
591
+ Create connection from YAML file with your credentials:
592
+
593
+ ` ` ` azurecli
594
+ az ml connection create --file connection.yaml --credentials username=<username> password=<password> --resource-group my-resource-group --workspace-name my-workspace
595
+ ```
596
+
597
+ Create environment
598
+
599
+ ``` azurecli
600
+ az ml environment create --name my-env --version 1 --file my_env.yml --conda-file conda_dep.yml --image mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu20.04 --resource-group my-resource-group --workspace-name my-workspace
601
+ ```
602
+
603
+ You can verify that the environment was successfully created
604
+
605
+ ``` azurecli
606
+ az ml environment show --name my-env --version 1 --resource-group my-resource-group --workspace-name my-workspace
607
+ ```
608
+
609
+ # [ Python SDK] ( #tab/python )
610
+
611
+ The following example creates an Azure Container Registry connection. A managed identity authenticates this connection:
612
+
613
+ ``` python
614
+ import os
615
+ from azure.ai.ml import MLClient
616
+ from azure.identity import DefaultAzureCredential
617
+ from azure.ai.ml.entities import Environment
618
+ from azure.ai.ml.entities import WorkspaceConnection
619
+ from azure.ai.ml.entities import UsernamePasswordConfiguration
620
+ from azureml.core.conda_dependencies import CondaDependencies
621
+ from azure.ai.ml import command
622
+
623
+ # Enter details of AML workspace
624
+ subscription_id = " <SUBSCRIPTION_ID>"
625
+ resource_group = " <RESOURCE_GROUP>"
626
+ workspace = " <AML_WORKSPACE_NAME>"
627
+
628
+ ml_client = MLClient( DefaultAzureCredential(), subscription_id, resource_group, workspace)
629
+ # Fetching secrets from env var to secure access, these secrets can be set outside or source code
630
+ registry_username = os.environ[" REGISTRY_USERNAME" ]
631
+ registry_password = os.environ[" REGISTRY_PASSWORD" ]
632
+ credentials = UsernamePasswordConfiguration(username = registry_username, password = registry_password)
633
+
634
+ # Create GenericContainerRegistry workspace connection for 3p registry
635
+ ws_connection = WorkspaceConnection(name = " <name>" , target = " <target>" , type = " GenericContainerRegistry" , credentials = credentials)
636
+ ml_client.connections.create_or_update(ws_connection)
637
+
638
+ # Create an environment
639
+ env_docker_conda = Environment(image = " <base image>" , conda_file = " <yml file>" , name = " docker-image-plus-conda-example" , description = " Environment created from a Docker image plus Conda environment." )
640
+ ml_client.environments.create_or_updat(env_docker_conda)
641
+
642
+ job = command(command = " echo 'hello world'" , environment = env_docker_conda,display_name = " v2-job-example" )
643
+ returned_job = ml_client.create_or_update(job)
644
+ ```
645
+
646
+ # [ Studio] ( #tab/azure-studio )
647
+
648
+ 1 . Navigate to the [ Azure Machine Learning studio] ( https://ml.azure.com/ ) .
649
+
650
+ 1 . Under ** Manage** in the left navigation, select ** Connections** and then select ** Create** .
651
+
652
+ 1 . Under ** Other resources types** , select ** Generic Container Registry** , input the required information, and then select ** Add connection**
653
+
654
+ ---
655
+
542
656
## Related content
543
657
544
658
If you use a data connection (Snowflake DB, Amazon S3, or Azure SQL DB), these articles offer more information:
0 commit comments