| author | cephalin |
|---|---|
| ms.service | azure-app-service |
| ms.devlang | java |
| ms.topic | quickstart |
| ms.date | 02/14/2025 |
| ms.author | cephalin |
In this quickstart, you learn how to deploy an ASP.NET app in a Windows image to Azure Container Registry from Visual Studio. You run the app in a custom container in Azure App Service.
Azure App Service provides predefined application stacks on Windows that run on Internet Information Services (IIS). These preconfigured application stacks lock down the operating system and prevent low-level access.
Custom Windows containers don't have these restrictions. Developers can use custom containers to give containerized applications full access to Windows functionality.
- Install Docker for Windows.
- Switch Docker to run Windows containers.
- Install Visual Studio 2022 with the ASP.NET and web development and Azure development workloads. In Visual Studio 2022 Community, ensure that you select the .NET Framework project and item templates component with ASP.NET and web development workload.
If you already installed Visual Studio 2022:
- Install the latest updates in Visual Studio by selecting Help > Check for Updates.
- Add the workloads in Visual Studio by selecting Tools > Get Tools and Features.
-
Open Visual Studio and then select Create a new project.
-
In Create a new project, select ASP.NET Web Application (.NET Framework) for
C#, and then select Next.:::image type="content" source="../../media/quickstart-custom-container/create-new-project.png" alt-text="Screenshot that shows the Create a new project dialog.":::
-
In Configure your new project > Project name, name the application
myfirstazurewebapp. Under Framework, select .NET Framework 4.8, and then select Create.:::image type="content" source="../../media/quickstart-custom-container/configure-web-app-project-container.png" alt-text="Screenshot that shows Configure your web app project.":::
-
You can deploy any type of ASP.NET web app to Azure. For this quickstart, select the MVC template.
-
Under Authentication, select None. Under Advanced, select Container support and clear Configure for HTTPS. Select Create.
:::image type="content" source="../../media/quickstart-custom-container/select-mvc-template-for-container.png" alt-text="Screenshot that shows the create ASP.NET Web Application dialog.":::
-
If the Dockerfile doesn't automatically open, open it by selecting Solution Explorer.
-
You need a supported parent image. Change the parent image by replacing the
FROMline with the following code, and then save the file:FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019 -
From the Visual Studio menu, select Debug > Start Without Debugging to run the web app locally.
:::image type="content" source="../../media/quickstart-custom-container/local-web-app.png" alt-text="Screenshot that shows the app running locally.":::
-
In Solution Explorer, right-click the
myfirstazurewebappproject, and then select Publish. -
In Target, select Docker Container Registry, and then select Next.
:::image type="content" source="../../media/quickstart-custom-container/select-docker-container-registry-visual-studio-2022.png" alt-text="Screenshot that shows the Select Docker Container Registry screen.":::
-
In Specific Target, select Azure Container Registry, and then select Next.
:::image type="content" source="../../media/quickstart-custom-container/publish-to-azure-container-registry-visual-studio-2022.png" alt-text="Screenshot that shows the Publish from project overview pane.":::
-
In Publish, select the correct subscription. To create a new container registry, select Create new in Container registries.
:::image type="content" source="../../media/quickstart-custom-container/create-new-azure-container-registry.png" alt-text="Screenshot that shows the Create new Azure Container Registry screen.":::
-
In Create new, select the correct subscription. Under Resource group, select New and type
myResourceGroupfor the name. Then, select OK. Under SKU, select Basic. Under Registry location, select a location for the registry, and then select Create.:::image type="content" source="../../media/quickstart-custom-container/new-azure-container-registry-details.png" alt-text="Screenshot that shows Azure Container Registry details.":::
-
In Publish, under Container Registry, select the registry that you created, and then select Finish.
:::image type="content" source="../../media/quickstart-custom-container/select-existing-azure-container-registry.png" alt-text="Screenshot that shows the Select existing Azure Container Registry screen.":::
Wait for deployment to finish. The Publish pane now shows the repository name. Select the Copy button to copy the Repository name for later.
:::image type="content" source="../../media/quickstart-custom-container/published-docker-repository-visual-studio-2022.png" alt-text="Screenshot that highlights the repository name.":::
-
Sign in to the Azure portal.
-
Select Create a resource in the upper-left corner of the Azure portal.
-
Under Popular services, select Create under Web App.
-
In Create Web App, select your subscription and resource group. You can create a new resource group if needed.
-
Provide an app name, such as
win-container-demo. For Publish, select Container. For Operating System, select Windows.:::image type="content" source="../../media/quickstart-custom-container/create-web-app-container.png" alt-text="Screenshot that shows how to create a web app for containers.":::
-
Select Next: Database > Next: Container.
-
For Image Source, select Docker Hub. For Image and tag, enter the repository name that you previously copied in Publish to Azure Container Registry.
:::image type="content" source="../../media/quickstart-custom-container/configure-web-app-container.png" alt-text="Screenshot that shows how to configure your web app for containers.":::
If you have a custom image for your web app in another location, like in Azure Container Registry or any other private repository, you can configure it here. Select Review + Create.
-
Verify all the details, and then select Create.
:::image type="content" source="../../media/quickstart-custom-container/web-app-container-create-start.png" alt-text="Screenshot that shows how to create your web app for containers.":::
Wait for Azure to create the required resources.
When the operation finishes, the Azure portal displays a notification.
:::image type="content" source="../../media/quickstart-custom-container/portal-create-finished.png" alt-text="Screenshot that shows deployment succeeded.":::
-
Select Go to resource.
-
In the overview, follow the link next to Default domain.
A new browser page opens.
:::image type="content" source="../../media/quickstart-custom-container/app-starting.png" alt-text="Screenshot that shows a Windows custom container starting.":::
Wait a few minutes and try again. Keep trying until you get the default ASP.NET home page.
:::image type="content" source="../../media/quickstart-custom-container/app-running-vs.png" alt-text="Screenshot that shows a Windows custom container running.":::
It can take some time for the Windows container to load. To see the progress, go to the following URL by replacing \<app_name> with the name of your app.
https://<app_name>.scm.azurewebsites.net/api/logstreamThe streamed logs look like this:
2018-07-27T12:03:11 Welcome, you are now connected to log-streaming service.
27/07/2018 12:04:10.978 INFO - Site: win-container-demo - Start container succeeded. Container: facbf6cb214de86e58557a6d073396f640bbe2fdec88f8368695c8d1331fc94b
27/07/2018 12:04:16.767 INFO - Site: win-container-demo - Container start complete
27/07/2018 12:05:05.017 INFO - Site: win-container-demo - Container start complete
27/07/2018 12:05:05.020 INFO - Site: win-container-demo - Container started successfully
-
In Visual Studio, go to Solution Explorer. Select Views > Home > Index.cshtml.
-
Find the
<div class="jumbotron">HTML tag near the top, and replace the entire element with the following code:<div class="jumbotron"> <h1>ASP.NET in Azure!</h1> <p class="lead">This is a simple app that we've built that demonstrates how to deploy a .NET app to Azure App Service.</p> </div>
-
To redeploy to Azure, right-click the myfirstazurewebapp project in Solution Explorer, and then select Publish.
-
On the publish pane, select Publish and wait for publishing to finish.
-
To tell App Service to pull in the new image from Docker Hub, restart the app. In the app pane in the Azure portal, select Restart > Yes.
:::image type="content" source="../../media/quickstart-custom-container/portal-restart-app.png" alt-text="Screenshot that shows App Service Overview with the Restart button highlighted.":::
-
Browse again to the custom container. As you refresh the page, the app should first revert to the Starting up page. It should then display the updated page.
:::image type="content" source="../../media/quickstart-custom-container/azure-web-app-updated.png" alt-text="Screenshot that shows the updated web app in Azure.":::
[!INCLUDE Clean-up Portal web app resources]
- Configure custom container
- Use managed identities for App Service and Azure Functions
- Application monitoring for Azure App Service overview
- Azure Monitor overview
- Secure with a custom domain and certificate
- Integrate your app with an Azure virtual network
- Use private endpoints for App Service apps
- Use Azure Container Registry with Azure Private Link
- Migrate to a Windows container in Azure
- Deploy a container with Azure Pipelines
- Deploy a container with GitHub Actions