0
0
Azurecloud~5 mins

ACR image building and pushing in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
Building and pushing container images to Azure Container Registry (ACR) lets you store your app images securely in the cloud. This helps you share and deploy your app easily without managing local storage.
When you want to save your app's container image in a private cloud registry for secure access.
When you need to share your container image with your team or deployment pipelines.
When you want to automate building and pushing images as part of your development workflow.
When you want to keep your container images close to your Azure cloud resources for faster deployments.
When you want to avoid managing your own container registry infrastructure.
Config File - Dockerfile
Dockerfile
FROM nginx:1.23.3-alpine
COPY ./html /usr/share/nginx/html
EXPOSE 80

This Dockerfile uses a small Nginx image as the base.

It copies your website files from the local 'html' folder into the container.

It exposes port 80 so the web server can receive traffic.

Commands
This command logs you into your Azure Container Registry named 'exampleRegistry' so you can push and pull images securely.
Terminal
az acr login --name exampleRegistry
Expected OutputExpected
Login Succeeded
--name - Specifies the name of your Azure Container Registry.
This builds your Docker image from the Dockerfile in the current folder and tags it with your registry URL and version 'v1'.
Terminal
docker build -t exampleRegistry.azurecr.io/my-app:v1 .
Expected OutputExpected
Sending build context to Docker daemon 3.07kB Step 1/3 : FROM nginx:1.23.3-alpine ---> 3f9f1b8f1a1a Step 2/3 : COPY ./html /usr/share/nginx/html ---> Using cache ---> 7a8b9c0d1e2f Step 3/3 : EXPOSE 80 ---> Running in 4c5d6e7f8g9h Removing intermediate container 4c5d6e7f8g9h ---> 1a2b3c4d5e6f Successfully built 1a2b3c4d5e6f Successfully tagged exampleRegistry.azurecr.io/my-app:v1
-t - Tags the image with the full registry path and version.
This pushes your tagged image to your Azure Container Registry so it can be used by your deployments.
Terminal
docker push exampleRegistry.azurecr.io/my-app:v1
Expected OutputExpected
The push refers to repository [exampleRegistry.azurecr.io/my-app] 1a2b3c4d5e6f: Pushed v1: digest: sha256:abcdef1234567890 size: 1234
This command lists all the image tags available in the 'my-app' repository in your Azure Container Registry to verify your push.
Terminal
az acr repository show-tags --name exampleRegistry --repository my-app
Expected OutputExpected
[ "v1" ]
--name - Specifies the Azure Container Registry name.
--repository - Specifies the repository name inside the registry.
Key Concept

If you remember nothing else from this pattern, remember: you must tag your image with your registry's full login server name before pushing it to Azure Container Registry.

Common Mistakes
Trying to push an image without logging into ACR first.
Docker cannot authenticate to your private registry, so the push fails.
Always run 'az acr login --name yourRegistry' before pushing images.
Tagging the image without the full registry login server URL.
Docker pushes to Docker Hub by default, not your Azure registry.
Tag images as 'yourRegistry.azurecr.io/imageName:tag' to push to ACR.
Not verifying the image push by listing tags in the registry.
You might think the push succeeded but the image is not available for deployment.
Use 'az acr repository show-tags' to confirm your image is in the registry.
Summary
Log in to your Azure Container Registry to authenticate your Docker client.
Build your Docker image and tag it with your registry's full login server name.
Push the tagged image to your Azure Container Registry.
Verify the image is stored by listing the repository tags in your registry.