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
@@ -24,7 +24,7 @@ This is the first tutorial in the series of articles that walk you through how t
24
24
> [!NOTE]
25
25
> You can also build and deploy this app using the [az containerapp up](/cli/azure/containerapp#az_containerapp_up) by following the instructions in the [Quickstart: Build and deploy an app to Azure Container Apps from a repository](quickstart-code-to-cloud.md) article. The `az containerapp up` command is a fast and convenient way to build and deploy your app to Azure Container Apps using a single command. However, it doesn't provide the same level of customization for your container app.
26
26
27
-
The next tutorial in the series will build and deploy the front end web application to Azure Container Apps.
27
+
The next tutorial in the series will build and deploy the front end web application to Azure Container Apps.
28
28
29
29
The following screenshot shows the output from the album API deployed in this tutorial.
30
30
@@ -145,23 +145,126 @@ cd code-to-cloud/src
145
145
146
146
## Create an Azure Container Registry
147
147
148
-
After the album API container image is built, create an Azure Container Registry (ACR) instance in your resource group to store it.
148
+
1. After the album API container image is built, create an Azure Container Registry (ACR) instance in your resource group to store it.
149
+
150
+
# [Bash](#tab/bash)
151
+
152
+
```azurecli
153
+
az acr create \
154
+
--resource-group $RESOURCE_GROUP \
155
+
--location $LOCATION \
156
+
--name $ACR_NAME \
157
+
--sku Basic
158
+
```
159
+
160
+
# [Azure PowerShell](#tab/azure-powershell)
161
+
162
+
```azurepowershell
163
+
$acr = New-AzContainerRegistry `
164
+
-ResourceGroupName $ResourceGroup `
165
+
-Location $Location `
166
+
-Name $ACRName `
167
+
-Sku Basic
168
+
```
169
+
170
+
---
171
+
172
+
1. Your container registry must allow Azure Resource Manager (ARM) audience tokens for authentication in order to use managed identity to pull images.
173
+
174
+
Use the following command to check if ARM tokens are allowed to access your Azure Container Registry (ACR).
175
+
176
+
# [Bash](#tab/bash)
177
+
178
+
```azurecli
179
+
az acr config authentication-as-arm show --registry "$ACR_NAME"
180
+
```
181
+
182
+
If ARM tokens are allowed, the command outputs the following.
183
+
184
+
```
185
+
{
186
+
"status": "enabled"
187
+
}
188
+
```
189
+
190
+
If the `status` is `disabled`, allow ARM tokens with the following command.
191
+
192
+
```azurecli
193
+
az acr config authentication-as-arm update --registry "$ACR_NAME" --status enabled
194
+
```
195
+
196
+
# [Azure PowerShell](#tab/azure-powershell)
197
+
198
+
```azurepowershell
199
+
$acr.AzureAdAuthenticationAsArmPolicyStatus
200
+
```
201
+
202
+
If the command returns `disabled`, allow ARM tokens with the following command.
203
+
204
+
```azurepowershell
205
+
Update-AzContainerRegistry `
206
+
-ResourceGroupName $acr.ResourceGroupName `
207
+
-Name $acr.Name `
208
+
-AzureAdAuthenticationAsArmPolicyStatus enabled
209
+
```
210
+
211
+
---
212
+
213
+
## Create a user-assigned managed identity
214
+
215
+
To avoid using administrative credentials, pull images from private repositories in Microsoft Azure Container Registry using managed identities for authentication. When possible, use a user-assigned managed identity to pull images.
149
216
150
217
# [Bash](#tab/bash)
151
218
152
-
```azurecli
153
-
az acr create \
154
-
--resource-group $RESOURCE_GROUP \
155
-
--name $ACR_NAME \
156
-
--sku Basic \
157
-
--admin-enabled true
158
-
```
219
+
1. Create a user-assigned managed identity. Before you run the following commands, choose a name for your managed identity and replace the `\<PLACEHOLDER\>` with the name.
1. Create a user-assigned managed identity. Before you run the following commands, choose a name for your managed identity and replace the `\<PLACEHOLDER\>` with the name.
1. Get the registry's resource ID. Before you run the following command, replace the *\<placeholders\>* with the resource group name for your registry.
az acr build --registry $ACRName --image $APIName .
289
+
The `az acr build` command does not have a PowerShell equivalent, but can be run in PowerShell.
290
+
291
+
To sign into Azure with the Azure CLI, run the following command and follow the prompts to complete the authentication process.
292
+
293
+
```powershell
294
+
az login
295
+
```
296
+
297
+
Then build the container.
298
+
299
+
```powershell
300
+
az acr build --registry $AcrName --image $APIName .
188
301
```
189
302
190
303
---
@@ -197,7 +310,7 @@ Output from the `az acr build` command shows the upload progress of the source c
197
310
198
311
## Build your application
199
312
200
-
The following steps, demonstrate how to build your container image locally using Docker and push the image to the new container registry.
313
+
The following steps show how to build your container image locally using Docker and push the image to the new container registry.
201
314
202
315
### Build the container with Docker
203
316
@@ -229,8 +342,8 @@ az acr login --name $ACR_NAME
229
342
230
343
# [Azure PowerShell](#tab/azure-powershell)
231
344
232
-
```powershell
233
-
az acr login --name $ACRName
345
+
```azurepowershell
346
+
Connect-AzContainerRegistry -Name $ACRName
234
347
```
235
348
236
349
---
@@ -239,13 +352,13 @@ Now, push the image to your registry.
239
352
240
353
# [Bash](#tab/bash)
241
354
242
-
```azurecli
355
+
```bash
243
356
docker push $ACR_NAME.azurecr.io/$API_NAME
244
357
```
245
358
246
359
# [Azure PowerShell](#tab/azure-powershell)
247
360
248
-
```powershell
361
+
```bash
249
362
docker push "$ACRName.azurecr.io/$APIName"
250
363
```
251
364
@@ -319,6 +432,8 @@ az containerapp create \
319
432
--target-port 8080 \
320
433
--ingress external \
321
434
--registry-server $ACR_NAME.azurecr.io \
435
+
--user-assigned "$IDENTITY_ID" \
436
+
--registry-identity "$IDENTITY_ID" \
322
437
--query properties.configuration.ingress.fqdn
323
438
```
324
439
@@ -328,67 +443,65 @@ az containerapp create \
328
443
329
444
* Without a `query` property, the call to `az containerapp create` returns a JSON response that includes a rich set of details about the application. Adding a query parameter filters the output to just the app's fully qualified domain name (FQDN).
330
445
446
+
* This command adds the `acrPull` role to your user-assigned managed identity, so it can pull images from your container registry.
447
+
331
448
# [Azure PowerShell](#tab/azure-powershell)
332
449
333
450
To create the container app, create template objects that you pass in as arguments to the `New-AzContainerApp` command.
334
451
335
-
Create a template object to define your container image parameters.
Create a registry credential object to define your registry information, and a secret object to define your registry password. The `PasswordSecretRef` refers to the `Name` in the secret object.
0 commit comments