Unable to get AAD authorization token with message: Please run ‘az login’ to setup account

When you are trying to authenticate with Azure container registry using sudo az acr login command, you may receive below error message:

linuxusr@dockerhostvm01:~$ sudo az acr login –name acr001
Unable to get AAD authorization tokens with message: Please run ‘az login’ to setup account.
Unable to get admin user credentials with message: Please run ‘az login’ to setup account.

Error response from daemon: Get “https://acr001.azurecr.io/v2/”: unauthorized: aad access token with sp failed client id must be guid
Login failed.

Unable to get AAD authorization token with message
linuxusr@dockerhostvm01:~$ az login
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code C64UXJA9T to authenticate.
[
{
“cloudName”: “AzureCloud”,
“homeTenantId”: “*****-8dab-4122-****-caadf41b**”,
“id”: “***2b17-4f6e-8b*****28cc**”,
“isDefault”: true,
“managedByTenants”: [],
“name”: “subscription0001”,
“state”: “Enabled”,
“tenantId”: “*****-8dab-*****-caadf41b64d7”,
“user”: {
“name”: “xyz@xyz.net”,
“type”: “user”
}
}
]

linuxusr@dockerhostvm01:~$ sudo az acr login –name acr001
Unable to get AAD authorization tokens with message: Please run ‘az login’ to setup account.
Unable to get admin user credentials with message: Please run ‘az login’ to setup account.

Error response from daemon: Get “https://acr001.azurecr.io/v2/”: unauthorized: aad access token with sp failed client id must be guid
Login failed.

To Fix this issue, Try to run sudo az login first and then try sudo az acr login –name acr001. You should get Login succeeded message this time.

sudo az login
linuxusr@dockerhostvm01:~$ sudo az acr login -n acr001
Login Succeeded