Pushing to Azure Container Registery (ACR) fails when following Tutorial

Siegfried Heintze 1,906 Reputation points
2022-12-21T21:57:21.167+00:00

I'm trying to follow this tutorial to push a custom image to the azure container registry.

  1. I execute "docker login $registry.azurecr.io" from a bash script and it says "Error: Cannot perform an interactive login from a non TTY device". However, it seems to work when using an interactive prompt (I get "Login Succeeded"). Is there a way I can do this from a script?
  2. So I abandon my bash script and continue with the interactive powershell prompt and after tagging my image I try "docker push $env:registry.azurecr.io/$env:image:latest" and I get "unauthorized: authentication required, visit https://aka.ms/acr/authorization for more information". I tried that URL and did not find anything helpful except a confirmation that the owner (me) should be able to push.
  3. However, "az acr build -g $rg --image $repo/$image:v1 --registry $registry --file Dockerfile ." works fine from my bash script with no login and I can deploy the resulting image with the command "az webapp create --name $web --resource-group $rg --plan $plan --deployment-container-image-name $registry.azurecr.io/$repo/$image:v1 -s $username -w $password" where $username & $password are the ACR credentials and $repo is the repository called "sample".
  4. Now I'm looking at this other tutorial: container-registry-get-started-docker-cli and it looks like I need to log into my ACR repository (named "demovisualstudiocicdforblazorserver") also... Why did not the first tutorial guide me to log into my ACR repo? OK, I'll try that in my bash script: it is failing! This might be the problem: export password=az acr credential show --resource-group $rg --name $registry --query passwords[0].value --output tsv
    export username=az acr credential show --resource-group $rg --name $registry --query username --output tsv
    az acr login -n $registry -u $username -p $password
    WARNING: Error response from daemon: Get "https://demovisualstudiocicdforblazorserver.azurecr.io/v2/": unauthorized: authentication required, visit https://aka.ms/acr/authorization for more information.
    ERROR: Login failed.

Why can I not login? Do I need to login to ACR to push? I don't need to login to ACR (or docker) if I do "acr build".

(5) Also, the second tutorial uses "samples"... I think this is the repository name and the first tutorial does not have a repository name. Is the use of a repository name like "samples" optional?

(6) I'd like to be able to see the docker push command in the first tutorial work for ACR. So far it works only when I'm using dockerhub instead of ACR.

Thanks

Siegfried

Azure Container Registry
Azure Container Registry
An Azure service that provides a registry of Docker and Open Container Initiative images.
511 questions
0 comments No comments
{count} votes

Accepted answer
  1. srbhatta-MSFT 8,586 Reputation points Microsoft Employee
    2022-12-22T08:55:40.837+00:00

    Hello @Siegfried Heintze ,
    Welcome to Microsoft QnA.

    1.Yes you can achieve this from a bash script. Are you passing the password? If yes, then could you please share the script with us. If not, then you can pass the --password-stdin flag to the docker login command and then pass the password as standard input. Here's an example of how you could do this in a bash script:

    #!/bin/bash  
    
    # Set the registry and password variables  
    registry=<your registry URL>  
    password=<your password>  
    
    # Run the docker login command and pass the password as standard input  
    echo $password | docker login $registry --password-stdin  
    

    Alternatively, you can store the password in a file and pass it to the --password-file flag like this:

    #!/bin/bash  
    
    # Set the registry and password file variables  
    registry=<your registry URL>  
    password_file=<path to password file>  
    
    # Run the docker login command and pass the password file  
    docker login $registry --password-file $password_file  
    

    Let us know if this works, then we can proceed onto the further queries of yours. Thank you.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Siegfried Heintze 1,906 Reputation points
    2022-12-23T01:11:29.397+00:00

    This works

     echo $DOCKERHUB_PASSWORD | docker login  -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD  
    

    This does not work:

      echo $DOCKERHUB_PASSWORD | docker login  $registry.azurecr.io -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD  
    

    But this works

    docker login  $registry.azurecr.io -u $ACR_username -p $ACR_password  
    

    I wish the tutorials would explain which credentials to use for "docker login".

    Mystery solved!

    1 person found this answer helpful.

  2. Siegfried Heintze 1,906 Reputation points
    2022-12-23T16:21:28.577+00:00

    When logging in with docker, be sure to use the ACR credentials and not the docker credentials.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.