Question

Difficulty: EasyManage Container Images in Azure Container Registry

You need to upload a locally built container image to a private Azure Container Registry (ACR) named contosoacr. Arrange the following commands in the correct sequence to authenticate your session and push the image to the registry.

  1. 1`az login`
  2. 2`az acr login --name contosoacr`
  3. 3`docker push contosoacr.azurecr.io/myimage:v1`

Answer

The correct sequence of commands is to first run `az login` to authenticate with Azure, then run `az acr login --name contosoacr` to authenticate with the specific registry, and finally run `docker push contosoacr.azurecr.io/myimage:v1` to upload the image.
The correct order requires first authenticating with Azure via `az login` to set up the CLI credentials context. Next, `az acr login --name contosoacr` uses that context to log the Docker daemon into the target registry. Finally, `docker push contosoacr.azurecr.io/myimage:v1` uploads the image now that authentication is successful.

Step-by-Step Solution

1
Run `az login`.
Establishes an active Azure session in the Azure CLI.
This is required so subsequent Azure CLI commands can access subscription details and credentials.
2
Run `az acr login --name contosoacr`.
Authenticates the local Docker client daemon with the `contosoacr` registry.
This command retrieves registry credentials using the active Azure CLI session to allow Docker operations.
3
Run `docker push contosoacr.azurecr.io/myimage:v1`.
Transfers the container image to the Azure Container Registry.
Since the local Docker CLI is authenticated, the push command can upload the image to the login server without authorization errors.

Key Concept

To push local container images to a private Azure Container Registry (ACR), you must first authenticate with Azure using `az login`, authenticate the local Docker client to the registry using `az acr login`, and then execute `docker push` with the registry's login server path.
Rate this question