user3807918
user3807918

Reputation: 375

Pull and Push images in Docker and Azure

I am trying to pull and push images between Docker Desktop and Azure and Visual Studio 2019.

currently I can push from VS2019 by Publish option and I can push to Docker and Azure Container Registry.

How do I pull from Azure to Docker? I believe there is an issue with security accounts between the 2 systems. After all, my Docker account is not my Azure account. I came across this article

https://learn.microsoft.com/en-us/azure/container-registry/container-registry-auth-service-principal

which contains a script. Is this the right article to solve my problem? I made a copy of the script but I am struggling to run it. If I save it to assignpermissions.sh file and run wsl ./assignpermissions.sh it complains that az does not exist.

So Is that the right article to help me (eventually) pull and push between Azure and Docker? How do I run the script when calling az is causing an error? Any other things I need to watch out for in the next step?

Upvotes: 0

Views: 1051

Answers (1)

Srijit_Bose-MSFT
Srijit_Bose-MSFT

Reputation: 1210

Log in to a registry

There are several ways to authenticate to your private container registry.

  • Azure CLI

The recommended method when working in a command line is with the Azure CLI command az acr login. For example, to log in to a registry named myregistry, log into the Azure CLI and then authenticate to your registry:

az login
az acr login --name myregistry
  • Azure PowerShell

The recommended method when working in PowerShell is with the Azure PowerShell cmdlet Connect-AzContainerRegistry. For example, to log in to a registry named myregistry, log into Azure and then authenticate to your registry:

Connect-AzAccount
Connect-AzContainerRegistry -Name myregistry

You can also log in with docker login. For example, you might have assigned a service principal to your registry for an automation scenario. When you run the following command, interactively provide the service principal appID (username) and password when prompted. For best practices to manage login credentials, see the docker login command reference:

docker login myregistry.azurecr.io

Both commands return Login Succeeded once completed.

Note: You might want to use Visual Studio Code with Docker extension for a faster and more convenient login.

Tip: Always specify the fully qualified registry name (all lowercase) when you use docker login and when you tag images for pushing to your registry. In the examples in this article, the fully qualified name is myregistry.azurecr.io.

Push the image to your registry

Now that you've tagged the image with the fully qualified path to your private registry, you can push it to the registry with docker push:

docker push myregistry.azurecr.io/samples/nginx

Pull the image from your registry

Use the docker pull command to pull the image from your registry:

docker pull myregistry.azurecr.io/samples/nginx

Upvotes: 1

Related Questions