Run a custom Windows container in Azure (Preview)
Azure App Service provides 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, changes to the global assembly cache, and so on (see Operating system functionality on Azure App Service). If your application requires more access than the preconfigured environment allows, you can deploy a custom Windows container instead. This quickstart shows how to deploy an ASP.NET app in a Windows image to Docker Hub from Visual Studio and run it in a custom container in Azure App Service.
To complete this tutorial:
- Sign up for a Docker Hub account
- Install Docker for Windows.
- Switch Docker to run Windows containers.
- Install Visual Studio 2017 with the ASP.NET and web development and Azure development workloads. If you've installed Visual Studio 2017 already:
- Install the latest updates in Visual Studio by clicking Help > Check for Updates.
- Add the workloads in Visual Studio by clicking Tools > Get Tools and Features.
Create an ASP.NET web app
In Visual Studio, create a project by selecting File > New > Project.
In the New Project dialog, select Visual C# > Web > ASP.NET Web Application (.NET Framework).
Name the application myFirstAzureWebApp, and then select OK.
You can deploy any type of ASP.NET web app to Azure. For this quickstart, select the MVC template, and make sure authentication is set to No Authentication.
Select Enable Docker Compose support.
If the Dockerfile file isn't opened automatically, open it from the Solution Explorer.
You need to use a supported parent image. Change the parent image by replacing the
FROM line with the following code and save the file:
From the menu, select Debug > Start without Debugging to run the web app locally.
Publish to Docker Hub
In the Solution Explorer, right-click the myFirstAzureWebApp project and select Publish.
The publish wizard is automatically launched. Select Container Registry > Docker Hub > Publish.
Supply your Docker Hub account credentials and click Save.
Wait for the deployment to complete. The Publish page now shows the repository name that you will use later in App Service.
Copy this repository name for later.
Sign in to Azure
Sign in to the Azure portal at https://portal.azure.com.
Create a Windows container app
Choose Create a resource in the upper left-hand corner of the Azure portal.
In the search box above the list of Azure Marketplace resources, search for and select Web App for Containers.
Provide an app name, such as win-container-demo, accept the defaults to create a new resource group, and click Windows (Preview) in the OS box.
Create an App Service plan by clicking App Service plan/Location > Create new. Give the new plan a name, accept the defaults, and click OK.
Click Configure container. In Image and optional tag, use the repository name you copied in Publish to Docker Hub, then click OK.
If you have a custom image elsewhere for your web application, such as in Azure Container Registry or in any other private repository, you can configure it here.
Click Create and wait for Azure to create the required resources.
Browse to the container app
When the Azure operation is complete, a notification box is displayed.
Click Go to resource.
In the app page, click the link under URL.
A new browser page is opened to the following page:
Wait a few minutes and try again, until you get the default ASP.NET home page:
Congratulations! You're running your first custom Windows container in Azure App Service.
See container start-up logs
It may take some time for the Windows container to load. To see the progress, navigate to the following URL by replacing <app_name> with the name of your app.
The streamed logs looks 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
Update locally and redeploy
From the Solution Explorer, open Views\Home\Index.cshtml.
<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 select Publish.
On the publish page, select Publish and wait for publishing to complete.
To tell App Service to pull in the new image from Docker Hub, restart the app. Back in the app page in the portal, click Restart > Yes.
Browse to the container app again. As you refresh the webpage, the app should revert to the "Starting up" page at first, then display the updated webpage again after a few minutes.
Use a different parent image
You are free to use a different custom Docker image to run your app. However, you must choose the right parent image for the framework you want:
- To deploy .NET Framework apps, use a parent image based on the Windows Server Core 2016 Long-Term Servicing Channel (LTSC) release.
- To deploy .NET Core apps, use a parent image based on the Windows Server Nano 2016 Long-Term Servicing Channel (LTSC) release.
It takes some time to download a parent image during app start-up. However, you can reduce start-up time by using one of the following parent images that are already cached in Azure App Service:
- microsoft/iis:windowsservercore-ltsc2016, latest
- microsoft/aspnet:4.7.2-windowsservercore-ltsc2016, 4.7.2, latest
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.