Run a custom Windows container in Azure
This tutorial will guide you about how to Run a custom Windows container in Azure. Azure App Service makes available pre-defined application stacks on Windows like ASP.NET or Node.js, running on IIS. The preconfigured Windows environment locks down the operating system from administrative access, software installations, transforms to the global assembly cache, and so on.
Create an ASP.NET web app
Create an ASP.NET web app by following the below mentioned steps:
- Firstly, Open Visual Studio and then choose Create a new project.
- In Create a new project, find and select ASP.NET Web Application (.NET Framework) for C#, then choose Next.
- Also, In Configure your new project, name the application as myfirstazurewebapp, and then choose Create.
- Now, You can choose to deploy any type of ASP.NET web app to Azure.
- choose Docker support, and make sure the authentication you choose is set to No Authentication. Choose Create.
- Furthermore, If the Dockerfile file isn’t going to open automatically, you have to open it from the Solution Explorer.
- Also, You need choose a supported parent image.
- Finally, From the Visual Studio menu, choose Debug > Start Without Debugging to run the web app locally.
Publish to Docker Hub
- Firstly, In Solution Explorer, right-click the myfirstazurewebapp project and choose Publish.
- Select App Service and then choose Publish.
- Then In Pick a publish target, choose Container Registry and Docker Hub, and then select Publish.
- Furthermore, Supply your Docker Hub account credentials and choose Save.
- Please Wait for the deployment to complete. The Publish page now displays the repository name to use later.
- Finally, Copy this repository name for later.
Create a Windows container app
- The first step always is to Sign in to the Azure portal.
- Select to Create a resource in the upper left-hand corner of the Azure portal.
- In the search box above the list of Azure Marketplace resources, start search for Web App for Containers, and choose Create.
- In Web App Create, select your subscription and a Resource Group. You can choose a new resource group if needed.
- Provide an app name, such as win-container-demo and select Windows for Operating System. choose Next: Docker to continue.
- For Image Source,select Docker Hub and for Image and tag, enter the repository name that you copied in Publish to Docker Hub.
- If you have a custom image some where else for your web application, such as in Azure Container Registry or in any other private repository, you can configure it here.
- choose Review and Create and then Create and wait for Azure to reach to the required resources.
Update locally and redeploy
- Go to the Visual Studio, in Solution Explorer, open Views > Home > Index.cshtml.
- Find the
<div class="jumbotron">
HTML tag near the top, and choose to replace the entire element with the code. - To redeploy to Azure, right-click the myfirstazurewebapp project in Solution Explorer and select Publish.
- On the publish page, choose Publish and wait for publishing to complete.
- To tell App Service to pull in any of the new image from Docker Hub, restart the app. Back in the app page in the portal, choose Restart > Yes.
- Start to Browse to the container app again. As you refresh the webpage, the app should reply to the “Starting up” page at first, then be displaying the updated webpage again after a few minutes when you complete.
Use a different parent image
You’re free to use a totally different custom Docker image to run your app. However, you must select the right parent image (base image) for the framework you want:
- Firstly, To deploy .NET Framework apps, try to choose a parent image based on the Windows Server Core 2019 Long-Term Servicing Channel (LTSC) release.
- Also, To deploy .NET Core apps, try to choose a parent image based on the Windows Server Nano 1809 Semi-Annual Servicing Channel (SAC) release.
It takes some time to download a parent image when app start-up. However, you can reduce start-up time by using one of the following parent images that are already available in Azure App Service:
- Firstly, mcr.microsoft.com/dotnet/framework/aspnet:4.7.2-windowsservercore-ltsc2019
- Subsequently, mcr.microsoft.com/windows/nanoserver:1809 – this image is the base container used across Microsoft ASP.NET Core Microsoft Windows Nano Server images.
Reference documentation – Run a custom Windows container in Azure (Preview)