Containerize .NET Core Application And Push It To Azure Container Registry Using Visual Studio

Introduction

 
Azure Container Registry is a private Container Registry on the Azure Platform. You can containerize your application and push it to the Azure Container Registry. Container-based services like Azure Container Instance, Azure WebApp, Azure Kubernetes Service, and Azure Service Fabric can pull the image and run it. You can also pull the image from anywhere outside the Azure platform like on-premises or other vendor clouds and run it. The images stored in Azure Container Registry are not publicly available and you must give explicit permission to users who should be pulling and using it.
 
You can create a .NET Core application, containerize it and push it to Azure Container Registry. All these steps you can do it using Visual Studio. You can enable Docker support for your solution and then publish it to the Azure Container Registry with few clicks in the Visual Studio. You can also use Docker commands to containerize an application and push it to the Azure Container Registry.
 
In this article, we will create a.NET Core application with Docker support enabled and push it to the Azure Container Registry. We will perform all these steps using Visual Studio. As a prerequisite, you should have Docker Desktop installed on your system. Below is the link for the previous article where we discussed how to create an Azure Container Registry. 

Creating a Docker Support Enabled .NET Core Web Application

 
Let us create a .NET Core MVC application and enable Docker support for the application. Open Visual Studio and click on Create a new project.
 
Containerize .NET Core Application and push it to Azure Container Registry using Visual Studio
 
Select ASP.NET Core Web Application. Click on Next.
 
Containerize .NET Core Application and push it to Azure Container Registry using Visual Studio
 
Provide the name of the project and click on Create.
 
Containerize .NET Core Application and push it to Azure Container Registry using Visual Studio
 
Select Web Application (Model-View-Controller). Select Enable Docker Support and click on Next.
 
Containerize .NET Core Application and push it to Azure Container Registry using Visual Studio
 
The default Web Application gets created. Now let us containerize the Default Web Application as-is. You may optionally choose to make some modifications in the default application and add your custom functionalities. Right-click on the Web Project and click on Publish.
 
Containerize .NET Core Application and push it to Azure Container Registry using Visual Studio
 
Click on Container Registry and then click on Select Existing Azure Container Registry.
 
Containerize .NET Core Application and push it to Azure Container Registry using Visual Studio
 
Select your Azure Subscription, Resource Group, and Azure Container Registry. Click on OK.
 
Containerize .NET Core Application and push it to Azure Container Registry using Visual Studio
 
Click on Publish. The default application will get containerized and be pushed to Azure Container Registry.
 
Containerize .NET Core Application and push it to Azure Container Registry using Visual Studio
 
Open Azure Portal and go to the Azure Container Registry. Click on Repositories. You can see the containerized image for the application.
 
Containerize .NET Core Application and push it to Azure Container Registry using Visual Studio
 

Conclusion

 
In this article, we learned how to containerize a .NET Core web application and push it to Azure Container Registry using Visual Studio. In the next article, we will containerize a .NET Core application, push it to Azure Container Registry using Docker commands. This technique would hold good for non-Microsoft based applications that are not supported on Visual Studio.