Azure Pipelines Docker task cannot log in to Azure Container Registry
unauthorized: Invalid clientid or client secret.Short answer
The service connection sends credentials that ACR rejects. Most often the service principal secret has expired, because it is valid for one year by default. Reset it and update the Docker registry service connection. Also check that the Docker ID is the service principal client ID and that the principal has the AcrPush role.
Fix it fast
1Find out which cause you have
Test the same credentials outside the pipeline. If docker login fails on your machine too, the credentials are wrong; if it works, the service connection holds something different.
docker login myregistry.azurecr.io --username "$SP_APP_ID" --password-stdin <<< "$SP_PASSWD"2Match what you see, then jump to its fix
- 1
The pipeline worked for months and then started failing without any changeThe service principal secret has expiredFix - 2
Fails on the first run after you created the connection by handThe Docker registry service connection has the wrong ID or passwordFix - 3
Pulls work, pushes are refusedThe service principal can pull but is not allowed to pushFix - 4
containerRegistry points at an ARM service connectionAn Azure Resource Manager connection is used where the Docker task needs a Docker registry oneFix
- 1
What does the error look like?
unauthorized: Invalid clientid or client secret.
Cause 1 of 4
The service principal secret has expired
1Check
A service principal created for ACR has one year of validity by default. If the secret is older than that, it has expired. A docker login with the stored secret from your own machine fails with the same message.
docker login myregistry.azurecr.io --username "$SP_APP_ID" --password "$OLD_SECRET"2Fix
Create a new secret with az ad sp credential reset, then paste the new password into the pipeline's service connection. The command can also set a longer expiry.
az ad sp credential reset --id $SP_APP_ID3Verify
Log in with the new secret and re-run the pipeline.
docker login myregistry.azurecr.io --username "$SP_APP_ID" --password "$NEW_SECRET"Confirmed by learn.microsoft.com
Cause 2 of 4
The Docker registry service connection has the wrong ID or password
1Check
For a Docker registry service connection, the Docker ID must be the service principal's client ID and the password its key (client secret). Use the appId value, not the display name.
az ad sp list --display-name MY_SP_NAME --query "[].appId" --output tsv2Fix
Edit the service connection: registry URL like https://myacr.azurecr.io, Docker ID is the appId, password is the client secret.
Docker Registry: https://myacr.azurecr.io
Docker ID: <service principal client ID>
Password: <service principal client secret>3Verify
Run the login step alone.
- task: Docker@2
inputs:
command: login
containerRegistry: dockerRegistryServiceConnection1Confirmed by learn.microsoft.com
Cause 3 of 4
The service principal can pull but is not allowed to push
1Check
The default role in the Microsoft sample script is acrpull, which only allows pulls; push and pull needs acrpush. Log in and try a pull, then a push, to see which one fails.
docker pull myregistry.azurecr.io/my-app:latest
docker push myregistry.azurecr.io/my-app:latest2Fix
Assign the AcrPush role (push and pull) to the principal on the registry.
ACR_ID=$(az acr show --name myacr --query id --output tsv)
az role assignment create --assignee $SP_APP_ID --scope $ACR_ID --role acrpush3Verify
Re-run the pipeline's push step.
docker push myregistry.azurecr.io/my-app:latestConfirmed by learn.microsoft.com
Cause 4 of 4
An Azure Resource Manager connection is used where the Docker task needs a Docker registry one
1Check
Microsoft's Docker@2 troubleshooting says the task supports only the Docker registry service connection, not an ARM one.
grep -n -A4 'Docker@2' azure-pipelines.yml2Fix
Create a Docker registry service connection of registry type Others, with your service principal's client ID and key as in the second cause, and reference it in containerRegistry.
- task: Docker@2
inputs:
command: buildAndPush
containerRegistry: dockerRegistryServiceConnection1
repository: my-app3Verify
The login lines of the task log should show success.
# Pipelines UI: open the Docker task logConfirmed by learn.microsoft.com
How do I stop it coming back?
- Put the secret's end date in a team calendar, or set a longer expiry when you reset it.
- Create a separate service principal for CI with AcrPush only on the one registry.
- Always test new credentials with docker login before saving them in the service connection.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- RaheebA consumer app shipped to both stores from one Flutter codebase on a .NET and Azure back end.
Related fixes
Servers
apk cannot find py-pip in an Alpine Docker image
py-pip (no such package):
On current Alpine releases there is no package called py-pip.
2 causes, each with a fixServers
ng serve runs in the container but localhost:4200 does not open
The browser cannot open localhost:4200 although ng serve is running in the container
ng serve listens on localhost by default, which inside a container is the container itself.
3 causes, each with a fixServers
Angular routes return 404 from nginx when you refresh or open a link
The home page loads, but refreshing /some/route shows an nginx 404
Angular routes like /users/42 are not files, so nginx looks for them on disk and returns 404.
3 causes, each with a fixServers
AH00558: Apache in Docker cannot reliably determine its fully qualified domain name
Set the 'ServerName' directive globally to suppress this message
AH00558 is a warning, not a crash.
2 causes, each with a fixServers
Apache in a Docker container logs AH01114 when it proxies to a backend
AH01114: HTTP: failed to make connection to backend: api
Apache's proxy worker could not open a connection to the address in ProxyPass.
5 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fix