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 a few clicks in 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 to the previous article where we discussed how to create an Azure Container Registry.

Working with 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.

MVC application

Select ASP.NET Core Web Application. Click on Next.

Web Application

Provide the name of the project and click on Create.

Create

Select Web Application (Model-View-Controller). Select Enable Docker Support and click on Next.

Enable Docker

The default Web Application gets created. Now let us containerize the Default Web Application as-is. You may optionally choose to make some modifications to the default application and add your custom functionalities. Right-click on the Web Project and click on Publish.

Web project

Click on Container Registry and then click on Select Existing Azure Container Registry.

 Container Registry

Select your Azure Subscription, Resource Group, and Azure Container Registry. Click on OK.

Azure Subscription

Click on Publish. The default application will get containerized and be pushed to Azure Container Registry.

Default application

Open the Azure Portal and go to the Azure Container Registry. Click on Repositories. You can see the containerized image for the application.

Open Azure Portal

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, and 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.


Similar Articles