|
| 1 | +--- |
| 2 | +title: Access from Container Instances |
| 3 | +description: Learn how to provide access to images in your private container registry from Azure Container Instances by using a Microsoft Entra service principal. |
| 4 | +ms.topic: article |
| 5 | +ms.custom: devx-track-azurecli |
| 6 | +ms.service: container-registry |
| 7 | +author: tejaswikolli-web |
| 8 | +ms.author: tejaswikolli |
| 9 | +ms.date: 10/31/2023 |
| 10 | +--- |
| 11 | + |
| 12 | +# Authenticate with Azure Container Registry from Azure Container Instances |
| 13 | + |
| 14 | +You can use a Microsoft Entra service principal to provide access to your private container registries in Azure Container Registry. |
| 15 | + |
| 16 | +In this article, you learn to create and configure a Microsoft Entra service principal with *pull* permissions to your registry. Then, you start a container in Azure Container Instances (ACI) that pulls its image from your private registry, using the service principal for authentication. |
| 17 | + |
| 18 | +## When to use a service principal |
| 19 | + |
| 20 | +You should use a service principal for authentication from ACI in **headless scenarios**, such as in applications or services that create container instances in an automated or otherwise unattended manner. |
| 21 | + |
| 22 | +For example, if you have an automated script that runs nightly and creates a [task-based container instance](../container-instances/container-instances-restart-policy.md) to process some data, it can use a service principal with pull-only permissions to authenticate to the registry. You can then rotate the service principal's credentials or revoke its access completely without affecting other services and applications. |
| 23 | + |
| 24 | +Service principals should also be used when the registry [admin user](container-registry-authentication.md#admin-account) is disabled. |
| 25 | + |
| 26 | +[!INCLUDE [container-registry-service-principal](../../includes/container-registry-service-principal.md)] |
| 27 | + |
| 28 | +## Authenticate using the service principal |
| 29 | + |
| 30 | +To launch a container in Azure Container Instances using a service principal, specify its ID for `--registry-username`, and its password for `--registry-password`. |
| 31 | + |
| 32 | +```azurecli-interactive |
| 33 | +az container create \ |
| 34 | + --resource-group myResourceGroup \ |
| 35 | + --name mycontainer \ |
| 36 | + --image mycontainerregistry.azurecr.io/myimage:v1 \ |
| 37 | + --registry-login-server mycontainerregistry.azurecr.io \ |
| 38 | + --registry-username <service-principal-ID> \ |
| 39 | + --registry-password <service-principal-password> |
| 40 | +``` |
| 41 | + |
| 42 | +>[!Note] |
| 43 | +> We recommend running the commands in the most recent version of the Azure Cloud Shell. Set `export MSYS_NO_PATHCONV=1` for running on-perm bash environment. |
| 44 | +
|
| 45 | +## Sample scripts |
| 46 | + |
| 47 | +You can find the preceding sample scripts for Azure CLI on GitHub, as well versions for Azure PowerShell: |
| 48 | + |
| 49 | +* [Azure CLI][acr-scripts-cli] |
| 50 | +* [Azure PowerShell][acr-scripts-psh] |
| 51 | + |
| 52 | +## Next steps |
| 53 | + |
| 54 | +The following articles contain additional details on working with service principals and ACR: |
| 55 | + |
| 56 | +* [Azure Container Registry authentication with service principals](container-registry-auth-service-principal.md) |
| 57 | +* [Authenticate with Azure Container Registry from Azure Kubernetes Service (AKS)](../aks/cluster-container-registry-integration.md) |
| 58 | + |
| 59 | +<!-- IMAGES --> |
| 60 | + |
| 61 | +<!-- LINKS - External --> |
| 62 | +[acr-scripts-cli]: https://github.com/Azure/azure-docs-cli-python-samples/tree/master/container-registry/create-registry/create-registry-service-principal-assign-role.sh |
| 63 | +[acr-scripts-psh]: https://github.com/Azure/azure-docs-powershell-samples/tree/master/container-registry |
| 64 | + |
| 65 | +<!-- LINKS - Internal --> |
0 commit comments