Home > Blockchain >  Why do I always `unauthorized: authentication required` when using bash to connect to Azure Containe
Why do I always `unauthorized: authentication required` when using bash to connect to Azure Containe

Time:06-15

I'm writing a simple bash script to pull an image from Azure Container Registry. If I type the command on the shell, I get authenticated and the images are pulled without any issue. However, when I run the same commands using the bash script, I get the unauthorized error.

Script

#!/bin/sh

sudo service docker start

docker logout
az logout

docker login myregistry.azurecr.io

sudo docker pull myregistry.azurecr.io/rstudio-server:0.1 

Error

Error response from daemon: Get "https://myregistry.azurecr.io/v2/": unauthorized: aad access token with sp failed client id must be guid
Error response from daemon: Head "https://myregistry.azurecr.io/v2/rstudio-server/manifests/0.1": unauthorized: authentication required, visit https://aka.ms/acr/authorization for more information.

I don't understand why it's happening even when I'm logged in.

CodePudding user response:

Tested in my environment working fine for me.

enter image description here

Make sure Your password will be stored unencrypted in /root/.docker/config.json if not try to authenticate it manually by providing username and password in bash script.

sudo service docker start

docker logout
az logout

docker login myregistry.azurecr.io --username $SP_APP_ID --password $SP_PASSWD

sudo docker pull myregistry.azurecr.io/rstudio-server:0.1 

You can also use the username and password of ACR as prvided in below picture inplace of APP_ID and SP_PASSWD

enter image description here

Would Suggest you to please follow this Microsoft Document for more information about authentication of ACR from Docker

  • Related