Edit

Share via


Quickstart: Run a custom container in Azure

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.

Prerequisites

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.

Create an ASP.NET web app

  1. Open Visual Studio and then select Create a new project.

  2. In Create a new project, select ASP.NET Web Application (.NET Framework) for C#, and then select Next.

    Screenshot that shows the Create a new project dialog.

  3. In Configure your new project > Project name, name the application myfirstazurewebapp. Under Framework, select .NET Framework 4.8, and then select Create.

    Screenshot that shows Configure your web app project.

  4. You can deploy any type of ASP.NET web app to Azure. For this quickstart, select the MVC template.

  5. Under Authentication, select None. Under Advanced, select Container support and clear Configure for HTTPS. Select Create.

    Screenshot that shows the create ASP.NET Web Application dialog.

  6. If the Dockerfile doesn't automatically open, open it by selecting Solution Explorer.

  7. You need a supported parent image. Change the parent image by replacing the FROM line with the following code, and then save the file:

    FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019
    
  8. From the Visual Studio menu, select Debug > Start Without Debugging to run the web app locally.

    Screenshot that shows the app running locally.

Publish to Azure Container Registry

  1. In Solution Explorer, right-click the myfirstazurewebapp project, and then select Publish.

  2. In Target, select Docker Container Registry, and then select Next.

    Screenshot that shows the Select Docker Container Registry screen.

  3. In Specific Target, select Azure Container Registry, and then select Next.

    Screenshot that shows the Publish from project overview pane.

  4. In Publish, select the correct subscription. To create a new container registry, select Create new in Container registries.

    Screenshot that shows the Create new Azure Container Registry screen.

  5. In Create new, select the correct subscription. Under Resource group, select New and type myResourceGroup for the name. Then, select OK. Under SKU, select Basic. Under Registry location, select a location for the registry, and then select Create.

    Screenshot that shows Azure Container Registry details.

  6. In Publish, under Container Registry, select the registry that you created, and then select Finish.

    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.

    Screenshot that highlights the repository name.

Create a Windows custom container

  1. Sign in to the Azure portal.

  2. Select Create a resource in the upper-left corner of the Azure portal.

  3. Under Popular services, select Create under Web App.

  4. In Create Web App, select your subscription and resource group. You can create a new resource group if needed.

  5. Provide an app name, such as win-container-demo. For Publish, select Container. For Operating System, select Windows.

    Screenshot that shows how to create a web app for containers.

  6. Select Next: Database > Next: Container.

  7. For Image Source, select Docker Hub. For Image and tag, enter the repository name that you previously copied in Publish to Azure Container Registry.

    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.

  8. Verify all the details, and then select Create.

    Screenshot that shows how to create your web app for containers.

    Wait for Azure to create the required resources.

Browse to the custom container

When the operation finishes, the Azure portal displays a notification.

Screenshot that shows deployment succeeded.

  1. Select Go to resource.

  2. In the overview, follow the link next to Default domain.

A new browser page opens.

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.

Screenshot that shows a Windows custom container running.

See container start-up logs

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/logstream

The 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

Update locally and redeploy

  1. In Visual Studio, go to Solution Explorer. Select Views > Home > Index.cshtml.

  2. 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>
    
  3. To redeploy to Azure, right-click the myfirstazurewebapp project in Solution Explorer, and then select Publish.

  4. On the publish pane, select Publish and wait for publishing to finish.

  5. 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.

    Screenshot that shows App Service Overview with the Restart button highlighted.

  6. 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.

    Screenshot that shows the updated web app in Azure.

Clean up resources

In the preceding steps, you created Azure resources in a resource group. If you don't expect to need these resources in the future, you can delete them by deleting the resource group:

  1. From the Azure portal menu or home page, select Resource groups > myResourceGroup.

  2. On the myResourceGroup pane, make sure that the listed resources are the ones you want to delete.

  3. Select Delete resource group. Type myResourceGroup in the text box to confirm, and then select Delete.

In this quickstart, you learn how to deploy an image from Azure Container Registry to Azure App Service.

App Service on Linux provides predefined application stacks on Linux with support for languages like .NET, Java, Node.js, and PHP. You can also use a custom Docker image to run your web app on an application stack that isn't already defined in Azure.

For more information about containerized applications in a serverless environment, see Container apps.

Prerequisites

Create a container registry

This quickstart uses Azure Container Registry as the registry. You can use other registries, but the steps might differ slightly.

Create a container registry by following the instructions in Quickstart: Create a private container registry by using the Azure portal.

Important

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 pane in the Azure portal. You need this setting to access App Service. For a managed identity, see Deploy from Azure Container Registry.

Sign in

  1. Open VS Code.

  2. Select the Azure logo on the activity bar, and then go to ACCOUNTS & TENANTS. Select Sign in to Azure and follow the instructions.

    Screenshot that shows how to sign in to Azure in VS Code.

  3. In the status bar at the bottom, verify that your Azure account email address is correct. Your subscription should be displayed in the APP SERVICE explorer.

  4. In the activity bar, select the Docker logo. In the REGISTRIES explorer, verify that the container registry you created appears.

    Screenshot that shows the Registries value with Azure expanded.

Check prerequisites

Verify that Docker is installed and running. If Docker is running, the following command displays the Docker version:

docker --version

Create and build image

  1. In VS Code, open an empty folder and add a file called Dockerfile. In the file, paste the content based on your desired language framework:

    In this file, the parent image is one of the built-in .NET containers of App Service.

    FROM mcr.microsoft.com/appsvc/dotnetcore:lts
    
    ENV PORT 8080
    EXPOSE 8080
    
    ENV ASPNETCORE_URLS "http://*:${PORT}"
    
    ENTRYPOINT ["dotnet", "/defaulthome/hostingstart/hostingstart.dll"]
    
  2. Open the command palette, and then type Docker Images: Build Image. Select Enter to run the command.

  3. In the image tag box, specify the tag you want in the following format: <acr-name>.azurecr.io/<image-name>:<tag>, where <acr-name> is the name of the container registry you created. Select Enter.

  4. When the image finishes building, select Refresh at the top of the IMAGES explorer and verify that the image built successfully.

    Screenshot that shows the built image with tag.

Deploy to container registry

  1. In the activity bar, select the Docker icon. In the IMAGES explorer, find the image you built.

  2. Expand the image, right-click on the tag you want, and select Push.

  3. Make sure the image tag begins with <acr-name>.azurecr.io and select Enter.

  4. When VS Code finishes pushing the image to your container registry, select Refresh at the top of the REGISTRIES explorer and verify that the image was pushed successfully.

    Screenshot that shows the image deployed to Azure Container Registry.

Deploy to App Service

  1. In the REGISTRIES explorer, expand the image, right-click the tag, and then select Deploy Image to Azure App Service.
  2. Follow the prompts to select a subscription, a globally unique app name, a resource group, and an App Service plan. Select B1 Basic for the pricing tier, and a region near you.

After deployment, your app is available at http://<app-name>.azurewebsites.net.

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 to use to host your website. This quickstart uses the Basic hosting plan on Linux infrastructure, which means the site is 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 a machine runs only your site. For pricing, see App Service pricing.

Browse the website

The Output panel shows the status of the deployment operations. When the operation finishes, select Open Site in the pop-up notification to open the site in your browser.

The App Service app pulls from the container registry every time it starts. If you rebuild your image, you just need to push it to your container registry, and the app pulls in the updated image when it restarts. To tell your app to pull in the updated image immediately, restart it.

To troubleshoot, go to I ran into an issue.

Clean up resources

In the preceding steps, you created Azure resources in a resource group. If you don't expect to need these resources in the future, you can delete them by deleting the resource group:

  1. From the Azure portal menu or home page, select Resource groups > myResourceGroup.

  2. On the myResourceGroup pane, make sure that the listed resources are the ones you want to delete.

  3. Select Delete resource group. Type myResourceGroup in the text box to confirm, and then select Delete.

Other Azure extensions:

In this quickstart, you learn how to deploy an image from Azure Container Registry to Azure App Service.

Azure App Service on Linux provides predefined application stacks on Linux with support for languages such as .NET, Java, Node.js, and PHP. You can also use a custom Docker image to run your web app on an application stack that isn't already defined in Azure.

For more information about containerized applications in a serverless environment, see Azure Container Apps overview.

Prerequisites

Clone the sample repository

Clone the the .NET 6.0 sample app by using the following command:

git clone https://github.com/Azure-Samples/dotnetcore-docs-hello-world.git

Push the image to Azure Container Registry

Make sure that you're in the cloned repository's root folder, which contains a Dockerfile.linux file.

  1. Sign in to the Azure CLI.

    az login
    
  2. Sign in to Azure Container Registry.

    az acr login -n <your_registry_name>
    
  3. Build the container image. This example uses the image name dotnetcore-docs-hello-world-linux.

    docker build -f Dockerfile.linux -t <your_registry_name>.azurecr.io/dotnetcore-docs-hello-world-linux . 
    
  4. Push the container image to Azure Container Registry.

    docker push <your_registry_name>.azurecr.io/dotnetcore-docs-hello-world-linux:latest
    

    Note

    The Dockerfile sets the port number to 80 internally. For more information, go to Configure custom container.

Deploy to Azure

  1. Sign in to the Azure portal.

  2. Type app services in the search. Under Services, select App Services.

    Screenshot that shows how to search for app services in the Azure portal.

  3. On the App Services pane, select Create > Web App.

  4. On the Basics tab, under Project details, select the correct subscription. To create a new resource group, select Create new. Type myResourceGroup for the name.

    Screenshot that shows the project details section where you select the Azure subscription and the resource group for the web app.

  5. Under Instance details:

    • Enter a globally unique name for your web app.
    • Select Container.
    • For Operating System, select Linux.
    • In Region, select the region from which you plan to serve your app.

    Screenshot that shows the instance details section where you provide a name for the virtual machine and select its region, image, and size.

  6. Under App Service Plan, select Create new. Enter myAppServicePlan for the name. To change to the Free tier, select Change size > Dev/Test > F1 > Apply.

    Screenshot that shows plan options.

  7. At the top of the pane, select the Container tab.

  8. On the Container tab, for Image Source, select Azure Container Registry. Under Azure Container Registry options, set the following values:

    • Registry: Select your container registry.
    • Image: Select dotnetcore-docs-hello-world-linux.
    • Tag: Select latest.

    Screenshot that shows Azure Container Registry options.

  9. Select Review + create at the bottom of the pane.

    Screenshot that shows the button at the bottom of the pane.

  10. After validation runs, select Create.

  11. After deployment finishes, select Go to resource.

    Screenshot that shows the button to go to the resource.

Browse to the app

Browse to the deployed application in your web browser at the URL http://<app-name>.azurewebsites.net.

Screenshot that shows the deployed application.

The App Service app pulls from the container registry each time it starts. If you rebuild your image, push it to your container registry. The app pulls in the updated image when it restarts. To tell your app to pull in the updated image immediately, restart it.

Clean up resources

In the preceding steps, you created Azure resources in a resource group. If you don't expect to need these resources in the future, you can delete them by deleting the resource group:

  1. From the Azure portal menu or home page, select Resource groups > myResourceGroup.

  2. On the myResourceGroup pane, make sure that the listed resources are the ones you want to delete.

  3. Select Delete resource group. Type myResourceGroup in the text box to confirm, and then select Delete.

In this quickstart, you learn how to deploy an ASP.NET app in a Windows image from Azure Container Registry to Azure App Service.

Azure App Service provides predefined application stacks on Windows, like ASP.NET or Node.js, 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.

Prerequisites

Clone the sample repository

Clone the the .NET 6.0 sample app by using the following command:

git clone https://github.com/Azure-Samples/dotnetcore-docs-hello-world.git

Push the image to Azure Container Registry

Make sure you're in the cloned repository's root folder. This repository contains a Dockerfile.windows file. This article uses Windows Nano Server Long Term Servicing Channel 2022 as the base operating system, and explicitly calls out the Windows base.

Note

Even though this container is a Windows container, the paths still need to use forward slashes. For more information, see Write a Dockerfile.

  1. Sign in to the Azure CLI.

    az login
    
  2. Sign in to Azure Container Registry.

    az acr login -n <your_registry_name>
    
  3. Build the container image. This example uses the image name dotnetcore-docs-hello-world-windows.

    docker build -f Dockerfile.windows -t <your_registry_name>.azurecr.io/dotnetcore-docs-hello-world-windows . 
    
  4. Push the container image to Azure Container Registry.

    docker push <your_registry_name>.azurecr.io/dotnetcore-docs-hello-world-windows:latest
    

    Note

    The Dockerfile sets the port number to 80 internally. For more information, see Configure custom container.

Deploy to Azure

  1. Sign in to the Azure portal.

  2. Enter app services in the search box. Under Services, select App Services.

    Screenshot that shows how to search for app services in the Azure portal.

  3. In App Services, select Create > Web App.

  4. On the Basics tab, under Project details, select the correct subscription. Select Create new. Enter myResourceGroup for the name.

    Screenshot that shows the Project details section where you select the Azure subscription and the resource group for the web app.

  5. Under Instance details:

    • Enter a globally unique name for your web app.
    • Select Container.
    • For Operating System, select Linux.
    • For Region, select the region from which you want to serve your app.

    Screenshot that shows the Instance details section where you provide a name for the virtual machine and select its region, image, and size.

  6. Under App Service Plan, select Create new. Enter myAppServicePlan for the name. To change the tier, select Explore pricing plans, select a plan, and choose Select at the bottom of the pane.

    Screenshot that shows App Service plan options.

  7. At the top of the pane, select the Container tab.

  8. On the Container tab, for Image Source, select Azure Container Registry. Under Azure Container Registry options, set the following values:

    • Registry: Select your container registry.
    • Image: Select dotnetcore-docs-hello-world-linux.
    • Tag: Select latest.

    Screenshot that shows Azure Container Registry options.

  9. Select Review + create at the bottom of the pane.

    Screenshot that shows the Review and create button at the bottom of the pane.

  10. After validation runs, select Create.

  11. After deployment finishes, select Go to resource.

    Screenshot that shows how to go to the resource.

Go to the app

Go to the deployed application in your web browser at the URL http://<app-name>.azurewebsites.net.

Screenshot that shows the Windows App Service.

The host operating system appears in the footer, which confirms that the app runs in a Windows container.

The App Service app pulls from the container registry each time it starts. If you rebuild your image, push it to your container registry. The app pulls in the updated image when it restarts. To tell your app to pull in the updated image immediately, restart it.

Clean up resources

In the preceding steps, you created Azure resources in a resource group. If you don't expect to need these resources in the future, you can delete them by deleting the resource group:

  1. From the Azure portal menu or home page, select Resource groups > myResourceGroup.

  2. On the myResourceGroup pane, make sure that the listed resources are the ones you want to delete.

  3. Select Delete resource group. Type myResourceGroup in the text box to confirm, and then select Delete.

In this quickstart, you learn how to deploy an ASP.NET app in a Windows image from Microsoft Artifact Registry to Azure App Service.

Azure App Service provides predefined application stacks on Windows that run on Internet Information Services (IIS). The 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.

Prerequisites

Connect to Azure

Sign in to your Azure account by using the Connect-AzAccount command and following the prompt:

Connect-AzAccount

Create a resource group

Create a resource group with the New-AzResourceGroup command. An Azure resource group is a logical container into which Azure resources are deployed and managed.

The following example creates a resource group named myResourceGroup in the eastus location. To see all supported locations for App Service, run the Get-AzLocation command.

New-AzResourceGroup -Name myResourceGroup -Location eastus

The command returns Login Succeeded.

Create your App Service plan

Create a new App Service plan by using the New-AzAppServicePlan command.

The following example creates an App Service plan named myAppServicePlan in the PremiumV3 pricing tier (-Tier PremiumV3). The -HyperV parameter specifies Windows container.

New-AzAppServicePlan -Name myAppServicePlan -Location eastus -ResourceGroupName myResourceGroup -Tier PremiumV3 -HyperV

Create your web app

Create a new app by using the New-AzWebApp command:

New-AzWebApp -Name myWebApp -AppServicePlan myAppServicePlan -Location eastus -ResourceGroupName myResourceGroup -ContainerImageName mcr.microsoft.com/azure-app-service/windows/parkingpage:latest
  • The Name parameter specifies the web app name.
  • The AppServicePlan parameter specifies the name of the App Service plan.
  • The Location parameter specifies the location.
  • The ResourceGroupName parameter specifies the name of the resource group.
  • The ContainerImageName parameter specifies a container image name and optional tag.

The command might take a few minutes to finish.

Browse to the app

Browse to the deployed application in your web browser at the URL http://<app-name>.azurewebsites.net.

Screenshot that shows Windows App Service.

The App Service app pulls from the container registry each time it starts. If you rebuild your image, push it to your container registry. The app pulls in the updated image when it restarts. To tell your app to pull in the updated image immediately, restart it.

Clean up resources

Remove the resource group by using the Remove-AzResourceGroup command:

Remove-AzResourceGroup myResourceGroup

In this quickstart, you learn how to deploy an ASP.NET app in a Windows image from Microsoft Artifact Registry to 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.

Prerequisites

Connect to Azure

Sign in to your Azure account. Use the az login command and follow the prompt:

az login

Create a resource group

Create a resource group by using the az group create command. An Azure resource group is a logical container into which Azure resources are deployed and managed.

The following example creates a resource group named myResourceGroup in the eastus location. To see all supported locations for App Service, run the az appservice list-locations command.

az group create --name myResourceGroup --location eastus

Create your App Service plan

Create an App Service plan in the resource group with the az appservice plan create command.

The following example creates an App Service plan named myAppServicePlan in the P1V3 pricing tier (--sku P1V3).

az appservice plan create --resource-group myResourceGroup --location eastus --name myAppServicePlan --hyper-v --sku p1v3

Note

If you run into the error "The behavior of this command has been altered by the following extension: appservice-kube", remove the appservice-kube extension.

Create your web app

Create a custom container web app in the myAppServicePlan App Service plan with the az webapp create command. Don't forget to replace myContainerApp with a unique app name (valid characters are a-z, 0-9, and -).

az webapp create --name myContainerApp --plan myAppServicePlan --resource-group myResourceGroup --deployment-container-image-name mcr.microsoft.com/azure-app-service/windows/parkingpage:latest
  • The Name parameter specifies the web app name.
  • The AppServicePlan parameter specifies the name of the App Service plan.
  • The Location parameter specifies the location.
  • The ResourceGroupName parameter specifies the name of the resource group.
  • The deployment-container-image-name parameter specifies a container image name and optional tag.

Browse to the app

Browse to the deployed application in your web browser at the URL http://<app-name>.azurewebsites.net.

Screenshot that shows Windows App Service.

The App Service app pulls from the container registry each time it starts. If you rebuild your image, push it to your container registry. The app pulls in the updated image when it restarts. To tell your app to pull in the updated image immediately, restart it.

Clean up resources

Remove the resource group by using the az group delete command:

az group delete --no-wait --name <resource_group>