Deploy .NET Core Application To Linux Containers On Azure Web App - Part Two

This article provides step by step guidance on how to pull a docker image from Azure Container Registry and deploy it on Azure Web App for Containers using Azure Pipelines.

Setting the Context

In the first article of this series, we developed an ASP.NET Core application and created a "Docker Compose" file to package the application in a Linux container. Then, we configured an Azure DevOps pipeline Continuous Integration build to push this image to Azure Container Registry. In this article, we will pull the image from the Azure Container Registry and deploy it to Azure Web App for Linux Containers using Azure Pipeline deployment build. Below is the link to the first article.

Follow these steps that will help deploy the container to Azure Web App for Linux Container.

Step 1

Create a Service Principal in Azure AD and configure necessary privileges. By default, the Azure Pipeline should be able to pull the images from Azure Container Registry and deploy it Web App. To make this work the right permissions should be configured. Service Principal will do the trick here.

Step 2

Add the Service Principal to the Web App and Azure Container Registry. The Service Principal should be added to the Web App and Azure Container Registry so that the pipeline can seamlessly connect and work.

Step 3

Create Azure Pipeline Deployment build. Azure Pipeline Continuous Deployment build will pull the image from Azure Container Registry and deploy it to Web App.

Step 4

Run the Azure pipeline Deployment build. This will deploy the .NET Core application packaged in Linux container to the Web App.
 

Create a Service Principal in Azure AD and configure necessary privileges

Go to Azure portal and click on Azure Active Directory.

Deploy .NET Core Application To Linux Containers On Azure Web App

Click on App registrations.

Deploy .NET Core Application To Linux Containers On Azure Web App

Click on New registration.

Deploy .NET Core Application To Linux Containers On Azure Web App

Provide a suitable Name and click on Register.

Deploy .NET Core Application To Linux Containers On Azure Web App

Click on API permissions.

 Deploy .NET Core Application To Linux Containers On Azure Web App

Click on Add a permission.

Deploy .NET Core Application To Linux Containers On Azure Web App

Select Visual Studio Team Services.

Deploy .NET Core Application To Linux Containers On Azure Web App

Check user_impersonation. Click Add permissions.

Deploy .NET Core Application To Linux Containers On Azure Web App

Click on Add a permission and select Azure Service Management and check user_impersonation as we did for Visual Studio Team Services. Click on Grant admin consent for Default Directory.

Deploy .NET Core Application To Linux Containers On Azure Web App
 
Now, the Service Principal is configured and can be used.
 

Add the Service Principal to Web App and Azure Container Registry

Go to the Azure Container Registry we created in the last article. Click on Access control (IAM).

Deploy .NET Core Application To Linux Containers On Azure Web App

Click on Add.

Deploy .NET Core Application To Linux Containers On Azure Web App

Click on Add role assignment.

Deploy .NET Core Application To Linux Containers On Azure Web App

Provide the right role and select the Service Principal we created earlier. Click on Save.

Deploy .NET Core Application To Linux Containers On Azure Web App

Go to the Web App we created in the last article. Follow exactly the same steps we did for Azure Container Registry to add the Service Principal.

Create Deployment Pipeline in Azure DevOps

Go to the project inside Azure DevOps. Click on Releases.

Deploy .NET Core Application To Linux Containers On Azure Web App

Click on New pipeline.

Deploy .NET Core Application To Linux Containers On Azure Web App

Select Azure App Service Deployment template and click Apply.

Deploy .NET Core Application To Linux Containers On Azure Web App

Select Azure Subscription and provide App type. Select App Service name where the container will be deployed. Provide Registry or Namespace for Azure Container Registry. Provide Repository Name and click on Save.

Deploy .NET Core Application To Linux Containers On Azure Web App

Click on Pipeline.

Deploy .NET Core Application To Linux Containers On Azure Web App

Click on Add an artifact.

Deploy .NET Core Application To Linux Containers On Azure Web App

Provide the source type as Azure Container Registry. Provide Service Connection, Resource Group, Azure Container Registry, and Repository.

Deploy .NET Core Application To Linux Containers On Azure Web App

Provide the default version as Specify at time of release creation. Click on Add.

Deploy .NET Core Application To Linux Containers On Azure Web App

Click on Save.

Deploy .NET Core Application To Linux Containers On Azure Web App

Now, the Deployment Build is released.

Run the Deployment build

Now, go to the Azure Repo and make some changes in the source code. Continuous Integration build that we created in the first part of the series will get triggered and a new image will be pushed to the Azure Container Registry as soon as we commit the changes. We can see below that a new image with tag 33 is pushed now in the registry.

Deploy .NET Core Application To Linux Containers On Azure Web App

Now, go to the Deployment Pipeline we have created. Click on Release.

Deploy .NET Core Application To Linux Containers On Azure Web App

Provide the version as the tag of the new image that got pushed to Azure Container Registry. Click on Create. The build will get triggered.

Deploy .NET Core Application To Linux Containers On Azure Web App

Once the build completes successfully, browse the Web App. The new changes can be seen.

Deploy .NET Core Application To Linux Containers On Azure Web App
 

Winding up

In this article, we deployed the .NET Core application packaged as a Docker container to Azure Web App for Linux. In the next article, we will see other easier options available by default in a Web App to support Continuous Deployment scenarios.