I'm trying to follow this
tutorial to push a custom image to the azure container registry
.
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?
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.
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".
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
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.
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!
This works and returns "Login Succeeded" - but with a warning "Using --password via the CLI is insecure, Use --password-stdin."
docker login $registry.azurecr.io -u $ACR_username -p $ACR_password