2

I'm using Azure CLI v2.0.62.

I do have multiple subscriptions - S1, S2, S3, S4 - in Azure on the single account.

I'm executing below script to insert dynamic value into repository:

az login
az acr build "ParentStorage" --platform windows -f Dockerfile -t ChildRepository:<dynamicValue>

Here, ParentStorage is of Storage Account type and ChileRepository is of Repository type.

At first, when login command gets executed, it gives me list of available subscription. But after executing az acr build... command it is throwing error message as below:

Error

The resource with name 'ParentStorage' and type 'Microsoft.ContainerRegistry/registries' could not be found in subscription 'Visual Studio Professional (ID)'.

What I have found till now is, it is trying to search under my Visual Studio subscription (S1). As S1 was the default subscription and repository was in S2. So I set S2 as default subscription and tried again but it didn't work.

Event when I tried to execute below command, it threw the same error:

az acr show --name ParentStorage

P.S.: I tried to login with specific subscription but unable to do so.

Please let me know what is I'm missing here.

I Love Stackoverflow
  • 6,738
  • 20
  • 97
  • 216
  • 1
    Are you saying that when you try `az account set -s S2` you get an error? You will need to be logged into the S2 subscription for your `az acr` commands to work. Another option is to create a new ACR in S1. – Ken W - Zero Networks Apr 19 '19 at 12:01
  • @KenWMSFT, no I didn't get an error in setting the default account to S2. But still when I executed the command `az acr build...` mentioned in quertion - at that time I got an error. – I Love Stackoverflow Apr 19 '19 at 12:20

4 Answers4

7

For your issue, it seems your registry is not in the current subscription. When you use the CLI command az login then you log in with a default subscription. For you, it seems the "Visual Studio Professional (ID)" is the default. You should check if your registry is in the current subscription. If not, you should set that subscription as the current subscription through the CLI command:

az account set --subscription subscription_id

Then I suggest you'd better check if the registry exists again with the CLI command:

az acr show -n acr_name

It will show the information of your registry. This time, you can build the image with the CLI command az acr build as you want.

Also, you can set the subscription in the login time with the parameter --subscription through the CLI command az login.

If you have more questions, please let me know. Or if you think it's helpful you can accept it as the answer.

Charles Xu
  • 29,862
  • 2
  • 22
  • 39
  • I have already tried this and also mentioned the same in the details I have provided (below the Error message). Thank you for the efforts, but please let me know if there is any other way I can try with. – I Love Stackoverflow Apr 21 '19 at 14:16
  • @PratikSoni What do you mean? The error shows the registry is not in the subscription "Visual Studio Professional (ID)". – Charles Xu Apr 22 '19 at 01:09
  • Sorry to keep you waiting. The issue that I couldn't get success last time is I still was looking into a wrong subscription. But now I'm able to get it as pointed now to a right subscription. Marked as answer. – I Love Stackoverflow Apr 22 '19 at 12:48
  • 1
    @PratikSoni Well, no one can be always careful on all the things. That's OK. – Charles Xu Apr 22 '19 at 12:52
  • Thanks, this saved me. Even though i haven't multiple subscriptions, the az account set -s was a solution for me. Thanks @CharlesXu – grava Feb 04 '22 at 11:19
4

I ran into this and found another issue. The service provider (SP) I was using only had the "Acr Push" role. I had to add the "Contributor" role to resolve the issue. So it appears "Acr Push" does not have enough permissions to see the ACR resource.

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • This worked for me as well, just make to run `az login --service-principal --username ...` again afterwards – Shaked KO Sep 07 '21 at 22:26
1

I managed to get over the same error adding the resource group in the command.

azure$ az acr build --registry mpregistry01 --resource-group cont-demo --image webimage .

I hope this works for you.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 08 '23 at 00:16
0

Just adding an additional thing by following the answer provided in here

We can use below command to build with specific subscription id so that whenever the multiple users want to execute this command with their different default subscription id, they don't need to make other subscription as their default.

az acr build --subscription $SubscriptionId -r $registry --platform Windows -f Dockerfile -t XYZ:v$version obj

Hope this helps others too.

I Love Stackoverflow
  • 6,738
  • 20
  • 97
  • 216