Run a custom container in Azure
Azure App Service provides pre-defined application stacks on Windows like ASP.NET or Node.js, running on IIS. The preconfigured Windows container (preview) environment locks down the operating system from administrative access, software installations, changes to the global assembly cache, and so on. For more information, 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. You run the app in a custom container in Azure App Service.
App Service on Windows containers is in preview.
To complete this tutorial:
Install Visual Studio 2019 with the ASP.NET and web development and Azure development workloads. If you've installed Visual Studio 2019 already:
- 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.
Create an ASP.NET web app
Create an ASP.NET web app by following these steps:
Open Visual Studio and then select Create a new project.
In Create a new project, find and choose ASP.NET Web Application (.NET Framework) for C#, then select Next.
In Configure your new project, name the application myfirstazurewebapp, and then select Create.
You can deploy any type of ASP.NET web app to Azure. For this quickstart, choose the MVC template.
Select Docker support, and make sure authentication is set to No Authentication. Select Create.
If the Dockerfile file isn't opened automatically, open it from the Solution Explorer.
You need a supported parent image. Change the parent image by replacing the
FROMline with the following code and save the file:
From the Visual Studio menu, select Debug > Start Without Debugging to run the web app locally.
Publish to Docker Hub
In Solution Explorer, right-click the myfirstazurewebapp project and select Publish.
Choose App Service and then select Publish.
In Pick a publish target, select Container Registry and Docker Hub, and then click Publish.
Supply your Docker Hub account credentials and select Save.
Wait for the deployment to complete. The Publish page now shows the repository name to use later.
Copy this repository name for later.
Create a Windows container app
Sign in to the Azure portal.
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 Web App for Containers, and select Create.
In Web App Create, choose your subscription and a Resource Group. You can create a new resource group if needed.
Provide an app name, such as win-container-demo and choose Windows for Operating System. Select Next: Docker to continue.
For Image Source, choose Docker Hub and for Image and tag, enter the repository name you copied in Publish to Docker Hub.
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.
Select Review and Create and then 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 overview of this resource, follow the link next to URL.
A new browser page opens 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
In Visual Studio, in 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 choose 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're free to use a different custom Docker image to run your app. However, you must choose the right parent image (base image) for the framework you want:
- To deploy .NET Framework apps, use a parent image based on the Windows Server Core 2019 Long-Term Servicing Channel (LTSC) release.
- To deploy .NET Core apps, use 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 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:
- mcr.microsoft.com/windows/nanoserver:1809 - this image is the base container used across Microsoft ASP.NET Core Microsoft Windows Nano Server images.
App Service on Linux provides pre-defined application stacks on Linux with support for languages such as .NET, PHP, Node.js and others. You can also use a custom Docker image to run your web app on an application stack that is not already defined in Azure. This quickstart shows you how to deploy an image from an Azure Container Registry (ACR) to App Service.
- An Azure account
- Visual Studio Code
- The Azure App Service extension for VS Code. You can use this extension to create, manage, and deploy Linux Web Apps on the Azure Platform as a Service (PaaS).
- The Docker extension for VS Code. You can use this extension to simplify the management of local Docker images and commands and to deploy built app images to Azure.
Create an image
To complete this quickstart, you will need a suitable web app image stored in an Azure Container Registry. Follow the instructions in Quickstart: Create a private container registry using the Azure portal, but use the
mcr.microsoft.com/azuredocs/go image instead of the
hello-world image. For reference, the sample Dockerfile is found in Azure Samples repo.
Be sure to set the Admin User option to Enable when you create the container registry. You can also set it from the Access keys section of your registry page in the Azure portal. This setting is required for App Service access.
Next, launch VS Code and log into your Azure account using the App Service extension. To do this, select the Azure logo in the Activity Bar, navigate to the APP SERVICE explorer, then select Sign in to Azure and follow the instructions.
Now you can check whether you have all the prerequisites installed and configured properly.
In VS Code, you should see your Azure email address in the Status Bar and your subscription in the APP SERVICE explorer.
Next, verify that you have Docker installed and running. The following command will display the Docker version if it is running.
Finally, ensure that your Azure Container Registry is connected. To do this, select the Docker logo in the Activity Bar, then navigate to REGISTRIES.
Deploy the image to Azure App Service
Now that everything is configured, you can deploy your image to Azure App Service directly from the Docker extension explorer.
Find the image under the Registries node in the DOCKER explorer, and expand it to show its tags. Right-click a tag and then select Deploy Image to Azure App Service.
From here, follow the prompts to choose a subscription, a globally unique app name, a Resource Group, and an App Service Plan. Choose B1 Basic for the pricing tier, and a region.
After deployment, your app is available at
A Resource Group is a named collection of all your application's resources in Azure. For example, a Resource Group can contain a reference to a website, a database, and an Azure Function.
An App Service Plan defines the physical resources that will be used to host your website. This quickstart uses a Basic hosting plan on Linux infrastructure, which means the site will be hosted on a Linux machine alongside other websites. If you start with the Basic plan, you can use the Azure portal to scale up so that yours is the only site running on a machine.
Browse the website
The Output panel will open during deployment to indicate the status of the operation. When the operation completes, find the app you created in the APP SERVICE explorer, right-click it, then select Browse Website to open the site in your browser.
Congratulations, you've successfully completed this quickstart!
Next, check out the other Azure extensions.
Or get them all by installing the Azure Tools extension pack.