You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -16,7 +16,15 @@ For this article, you learn more about managed identities and how to:
16
16
> * Grant the identity access to an Azure container registry
17
17
> * Use the managed identity to access the registry and pull a container image
18
18
19
-
To create the Azure resources, this article requires that you run the Azure CLI version 2.0.55 or later. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI][azure-cli].
19
+
### [Azure CLI](#tab/azure-cli)
20
+
21
+
To create the Azure resources, this article requires that you run the Azure CLI version 2.0.55 or later. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI][azure-cli-install].
22
+
23
+
### [Azure PowerShell](#tab/azure-powershell)
24
+
25
+
To create the Azure resources, this article requires that you run the Azure PowerShell module version 7.5.0 or later. Run `Get-Module Az -ListAvailable` to find the version. If you need to install or upgrade, see [Install Azure PowerShell module][azure-powershell-install].
26
+
27
+
---
20
28
21
29
To set up a container registry and push a container image to it, you must also have Docker installed locally. Docker provides packages that easily configure Docker on any [macOS][docker-mac], [Windows][docker-windows], or [Linux][docker-linux] system.
22
30
@@ -30,17 +38,29 @@ Then, use the identity to authenticate to any [service that supports Azure AD au
30
38
31
39
## Create a container registry
32
40
41
+
### [Azure CLI](#tab/azure-cli)
42
+
33
43
If you don't already have an Azure container registry, create a registry and push a sample container image to it. For steps, see [Quickstart: Create a private container registry using the Azure CLI](container-registry-get-started-azure-cli.md).
34
44
35
45
This article assumes you have the `aci-helloworld:v1` container image stored in your registry. The examples use a registry name of *myContainerRegistry*. Replace with your own registry and image names in later steps.
36
46
47
+
### [Azure PowerShell](#tab/azure-powershell)
48
+
49
+
If you don't already have an Azure container registry, create a registry and push a sample container image to it. For steps, see [Quickstart: Create a private container registry using Azure PowerShell](container-registry-get-started-powershell.md).
50
+
51
+
This article assumes you have the `aci-helloworld:v1` container image stored in your registry. The examples use a registry name of *myContainerRegistry*. Replace with your own registry and image names in later steps.
52
+
53
+
---
54
+
37
55
## Create a Docker-enabled VM
38
56
39
-
Create a Docker-enabled Ubuntu virtual machine. You also need to install the [Azure CLI](/cli/azure/install-azure-cli) on the virtual machine. If you already have an Azure virtual machine, skip this step to create the virtual machine.
57
+
### [Azure CLI](#tab/azure-cli)
58
+
59
+
Create a Docker-enabled Ubuntu virtual machine. You also need to install the [Azure CLI][azure-cli-install] on the virtual machine. If you already have an Azure virtual machine, skip this step to create the virtual machine.
40
60
41
61
Deploy a default Ubuntu Azure virtual machine with [az vm create][az-vm-create]. The following example creates a VM named *myDockerVM* in an existing resource group named *myResourceGroup*:
42
62
43
-
```azurecli
63
+
```azurecli-interactive
44
64
az vm create \
45
65
--resource-group myResourceGroup \
46
66
--name myDockerVM \
@@ -51,6 +71,32 @@ az vm create \
51
71
52
72
It takes a few minutes for the VM to be created. When the command completes, take note of the `publicIpAddress` displayed by the Azure CLI. Use this address to make SSH connections to the VM.
53
73
74
+
### [Azure PowerShell](#tab/azure-powershell)
75
+
76
+
Create a Docker-enabled Ubuntu virtual machine. You also need to install the [Azure PowerShell][azure-powershell-install] on the virtual machine. If you already have an Azure virtual machine, skip this step to create the virtual machine.
77
+
78
+
Deploy a default Ubuntu Azure virtual machine with [New-AzVM][new-azvm]. The following example creates a VM named *myDockerVM* in an existing resource group named *myResourceGroup*. You will be prompted for a user name that will be used when you connect to the VM. Specify *azureuser* as the user name. You will also be asked for a password, which you can leave blank. Password login for the VM is disabled when using an SSH key.
79
+
80
+
```azurepowershell-interactive
81
+
$vmParams = @{
82
+
ResourceGroupName = 'MyResourceGroup'
83
+
Name = 'myDockerVM'
84
+
Image = 'UbuntuLTS'
85
+
PublicIpAddressName = 'myPublicIP'
86
+
GenerateSshKey = $true
87
+
SshKeyName = 'mySSHKey'
88
+
}
89
+
New-AzVM @vmParams
90
+
```
91
+
92
+
It takes a few minutes for the VM to be created. When the command completes, run the following command to get the public IP address. Use this address to make SSH connections to the VM.
After the VM is running, make an SSH connection to the VM. Replace *publicIpAddress* with the public IP address of your VM.
@@ -72,33 +118,42 @@ After installation, run the following command to verify that Docker is running p
72
118
sudo docker run -it mcr.microsoft.com/hello-world
73
119
```
74
120
75
-
Output:
76
-
77
-
```
121
+
```output
78
122
Hello from Docker!
79
123
This message shows that your installation appears to be working correctly.
80
124
[...]
81
125
```
126
+
### [Azure CLI](#tab/azure-cli)
82
127
83
128
### Install the Azure CLI
84
129
85
130
Follow the steps in [Install Azure CLI with apt](/cli/azure/install-azure-cli-apt) to install the Azure CLI on your Ubuntu virtual machine. For this article, ensure that you install version 2.0.55 or later.
86
131
132
+
### [Azure PowerShell](#tab/azure-powershell)
133
+
134
+
### Install the Azure PowerShell
135
+
136
+
Follow the steps in [Installing PowerShell on Ubuntu][powershell-install] and [Install the Azure Az PowerShell module][azure-powershell-install] to install PowerShell and Azure PowerShell on your Ubuntu virtual machine. For this article, ensure that you install Azure PowerShell version 7.5.0 or later.
137
+
138
+
---
139
+
87
140
Exit the SSH session.
88
141
89
142
## Example 1: Access with a user-assigned identity
90
143
91
144
### Create an identity
92
145
93
-
Create an identity in your subscription using the [az identity create](/cli/azure/identity#az-identity-create) command. You can use the same resource group you used previously to create the container registry or virtual machine, or a different one.
146
+
### [Azure CLI](#tab/azure-cli)
147
+
148
+
Create an identity in your subscription using the [az identity create][az-identity-create] command. You can use the same resource group you used previously to create the container registry or virtual machine, or a different one.
94
149
95
150
```azurecli-interactive
96
151
az identity create --resource-group myResourceGroup --name myACRId
97
152
```
98
153
99
-
To configure the identity in the following steps, use the [az identity show][az_identity_show] command to store the identity's resource ID and service principal ID in variables.
154
+
To configure the identity in the following steps, use the [az identity show][az-identity-show] command to store the identity's resource ID and service principal ID in variables.
100
155
101
-
```azurecli
156
+
```azurecli-interactive
102
157
# Get resource ID of the user-assigned identity
103
158
userID=$(az identity show --resource-group myResourceGroup --name myACRId --query id --output tsv)
Create an identity in your subscription using the [New-AzUserAssignedIdentity][new-azuserassignedidentity] cmdlet. You can use the same resource group you used previously to create the container registry or virtual machine, or a different one.
To configure the identity in the following steps, use the [Get-AzUserAssignedIdentity][get-azuserassignedidentity] cmdlet to store the identity's resource ID and service principal ID in variables.
### Grant identity access to the container registry
130
230
231
+
### [Azure CLI](#tab/azure-cli)
232
+
131
233
Now configure the identity to access your container registry. First use the [az acr show][az-acr-show] command to get the resource ID of the registry:
132
234
133
-
```azurecli
235
+
```azurecli-interactive
134
236
resourceID=$(az acr show --resource-group myResourceGroup --name myContainerRegistry --query id --output tsv)
135
237
```
136
238
137
-
Use the [az role assignment create][az-role-assignment-create] command to assign the AcrPull role to the registry. This role provides [pull permissions](container-registry-roles.md) to the registry. To provide both pull and push permissions, assign the ACRPush role.
239
+
Use the [az role assignment create][az-role-assignment-create] command to assign the AcrPull role to the identity. This role provides [pull permissions](container-registry-roles.md) to the registry. To provide both pull and push permissions, assign the AcrPush role.
138
240
139
-
```azurecli
241
+
```azurecli-interactive
140
242
az role assignment create --assignee $spID --scope $resourceID --role acrpull
141
243
```
142
244
245
+
### [Azure PowerShell](#tab/azure-powershell)
246
+
247
+
Now configure the identity to access your container registry. First use the [Get-AzContainerRegistry][get-azcontainerregistry] command to get the resource ID of the registry:
Use the [New-AzRoleAssignment][new-azroleassignment] cmdlet to assign the AcrPull role to the identity. This role provides [pull permissions](container-registry-roles.md) to the registry. To provide both pull and push permissions, assign the AcrPush role.
SSH into the Docker virtual machine that's configured with the identity. Run the following Azure CLI commands, using the Azure CLI installed on the VM.
146
266
147
267
First, authenticate to the Azure CLI with [az login][az-login], using the identity you configured on the VM. For `<userID>`, substitute the ID of the identity you retrieved in a previous step.
@@ -162,13 +282,40 @@ You should see a `Login succeeded` message. You can then run `docker` commands w
SSH into the Docker virtual machine that's configured with the identity. Run the following Azure PowerShell commands, using the Azure PowerShell installed on the VM.
288
+
289
+
First, authenticate to the Azure PowerShell with [Connect-AzAccount][connect-azaccount], using the identity you configured on the VM. For `-AccountId` specify a client ID of the identity.
Then, authenticate to the registry with [Connect-AzContainerRegistry][connect-azcontainerregistry]. When you use this command, the Azure PowerShell uses the Active Directory token created when you ran `Connect-AzAccount` to seamlessly authenticate your session with the container registry. (Depending on your VM's setup, you might need to run this command and docker commands with `sudo`.)
You should see a `Login succeeded` message. You can then run `docker` commands without providing credentials. For example, run [docker pull][docker-pull] to pull the `aci-helloworld:v1` image, specifying the login server name of your registry. The login server name consists of your container registry name (all lowercase) followed by `.azurecr.io` - for example, `mycontainerregistry.azurecr.io`.
Use the [Get-AzVM][get-azvm] command to set a variable to the value of `principalId` (the service principal ID) of the VM's identity, to use in later steps.
### Grant identity access to the container registry
182
346
347
+
### [Azure CLI](#tab/azure-cli)
348
+
183
349
Now configure the identity to access your container registry. First use the [az acr show][az-acr-show] command to get the resource ID of the registry:
184
350
185
-
```azurecli
351
+
```azurecli-interactive
186
352
resourceID=$(az acr show --resource-group myResourceGroup --name myContainerRegistry --query id --output tsv)
187
353
```
188
354
189
-
Use the [az role assignment create][az-role-assignment-create] command to assign the AcrPull role to the identity. This role provides [pull permissions](container-registry-roles.md) to the registry. To provide both pull and push permissions, assign the ACRPush role.
355
+
Use the [az role assignment create][az-role-assignment-create] command to assign the AcrPull role to the identity. This role provides [pull permissions](container-registry-roles.md) to the registry. To provide both pull and push permissions, assign the AcrPush role.
190
356
191
-
```azurecli
357
+
```azurecli-interactive
192
358
az role assignment create --assignee $spID --scope $resourceID --role acrpull
193
359
```
194
360
361
+
### [Azure PowerShell](#tab/azure-powershell)
362
+
363
+
Now configure the identity to access your container registry. First use the [[Get-AzContainerRegistry][get-azcontainerregistry] command to get the resource ID of the registry:
Use the [New-AzRoleAssignment][new-azroleassignment] cmdlet to assign the AcrPull role to the identity. This role provides [pull permissions](container-registry-roles.md) to the registry. To provide both pull and push permissions, assign the AcrPush role.
SSH into the Docker virtual machine that's configured with the identity. Run the following Azure CLI commands, using the Azure CLI installed on the VM.
198
382
199
383
First, authenticate the Azure CLI with [az login][az-login], using the system-assigned identity on the VM.
@@ -213,6 +397,29 @@ You should see a `Login succeeded` message. You can then run `docker` commands w
SSH into the Docker virtual machine that's configured with the identity. Run the following Azure PowerShell commands, using the Azure PowerShell installed on the VM.
403
+
404
+
First, authenticate the Azure PowerShell with [Connect-AzAccount][connect-azaccount], using the system-assigned identity on the VM.
405
+
406
+
```azurepowershell
407
+
Connect-AzAccount -Identity
408
+
```
409
+
410
+
Then, authenticate to the registry with [Connect-AzContainerRegistry][connect-azcontainerregistry]. When you use this command, the PowerShell uses the Active Directory token created when you ran `Connect-AzAccount` to seamlessly authenticate your session with the container registry. (Depending on your VM's setup, you might need to run this command and docker commands with `sudo`.)
You should see a `Login succeeded` message. You can then run `docker` commands without providing credentials. For example, run [docker pull][docker-pull] to pull the `aci-helloworld:v1` image, specifying the login server name of your registry. The login server name consists of your container registry name (all lowercase) followed by `.azurecr.io` - for example, `mycontainerregistry.azurecr.io`.
0 commit comments