How To Push a Docker Image to Microsoft Azure ACR With Azure Devops Pipelines
Docker has become a widely used tool for packaging and deploying applications in containers. Microsoft Azure provides a fully managed private Docker registry called Azure Container Registry (ACR) that allows you to store and manage your Docker images in the cloud. In this blog post, I will show you how to build and push Docker images to ACR using Azure DevOps Pipelines.
Prerequisites ;
- Azure Account
- Azure Devops Organization
Before we begin, you will need to create an ACR instance in your Azure subscription. You can do this using the Azure CLI, Azure Portal, Azure Resource Manager (ARM) templates, or IAC (Terraform). In this example, I used Terraform to create the resource group and ACR.
You can check out my Terraspace codes on GitHub at https://github.com/hkaanturgut/Building-and-Pushing-Docker-images-to-Azure-container-Registry-With-Azure-DevOps-Pipeline/tree/main/azure_terraspace_ecr.
Next, I have my Python app and Dockerfile. You can check it out on GitHub at https://github.com/hkaanturgut/Building-and-Pushing-Docker-images-to-Azure-container-Registry-With-Azure-DevOps-Pipeline/tree/main/pyhton.app%20docker
I then created an organization and project on Azure DevOps at https://dev.azure.com/.
Once my project was created, I navigated to the Pipeline section and selected GitHub as my code repository.
At the next step , from the Select tab I chose my repository.
I then chose the Docker option for building and pushing the image to ACR. I selected my ACR instance that I created earlier, and the pipeline automatically named my image. You can change the name to your preference.
The magic happened when Azure DevOps automatically created a pipeline from my code.
I saved and ran it, and my image was successfully created and pushed to my ACR. The pipeline YAML file was also automatically pushed to my GitHub repository.
And there you have it, your image has been deployed to ACR.
In this article, we explored a method for pushing Docker images to Azure Container Registry (ACR) using Azure DevOps Pipelines.
And there you have it, your image has been deployed to ACR. With this method, you can easily build and push Docker images to ACR using Azure DevOps Pipelines without the need for additional services such as Azure CodeBuild or CodeDeploy. Additionally, this approach remains within the free tier of Azure, and you have the flexibility to switch to different cloud providers if necessary. The next step would be to utilize these Docker images in the cloud, such as setting up a website in an Azure Virtual Machine and further reducing overall cloud costs.
Thanks for reading! Stay tuned for more updates and tutorials on this topic.