How to Push Docker Image to Azure Container Registry (ACR)
To push an image to Azure Container Registry (ACR), first log in to your ACR using
az acr login --name <registryName>. Then tag your local Docker image with your ACR login server and push it using docker push <loginServer>/<imageName>:<tag>.Syntax
Follow these steps to push an image to ACR:
- Login to ACR: Use
az acr login --name <registryName>to authenticate your Docker client with your Azure Container Registry. - Tag the image: Use
docker tag <localImage> <loginServer>/<imageName>:<tag>to prepare your image for pushing. - Push the image: Use
docker push <loginServer>/<imageName>:<tag>to upload the image to ACR.
bash
az acr login --name <registryName>
docker tag <localImage> <loginServer>/<imageName>:<tag>
docker push <loginServer>/<imageName>:<tag>Example
This example shows how to push a Docker image named myapp with tag v1 to an Azure Container Registry named myregistry.
bash
az acr login --name myregistry
docker tag myapp myregistry.azurecr.io/myapp:v1
docker push myregistry.azurecr.io/myapp:v1Output
Login Succeeded
digest: sha256:abc123... size: 1234
The push refers to repository [myregistry.azurecr.io/myapp]
...
v1: digest: sha256:abc123... size: 1234
Common Pitfalls
Common mistakes when pushing images to ACR include:
- Not logging in to ACR before pushing, causing authentication errors.
- Using the wrong
loginServerURL; it must match your registry's login server. - Forgetting to tag the image with the ACR login server before pushing.
- Not having Docker installed or running on your machine.
bash
docker push myapp:v1 # Wrong: pushing without tagging with ACR login server # Correct: docker tag myapp myregistry.azurecr.io/myapp:v1 docker push myregistry.azurecr.io/myapp:v1
Quick Reference
| Command | Purpose |
|---|---|
| az acr login --name | Authenticate Docker client with ACR |
| docker tag | Tag local image for ACR |
| docker push | Push image to ACR |
Key Takeaways
Always log in to your Azure Container Registry before pushing images.
Tag your local Docker image with your ACR login server URL before pushing.
Use the exact login server URL provided by your ACR instance.
Ensure Docker is installed and running on your machine.
Check for authentication errors if push fails and retry login.