You have several different approaches available for deploying a Azure Web App. The traditional approach is solution based deployment which is simply deploying your code to an Azure Web App. The second option which I find more interesting is the ability to deploy a container that runs within the Azure Web App. Before diving in to deep I would like to first describe some basics around Containers.
A container as a self sustaining instance of your application. The container instance contains all the required dependencies for an application to run. In the older approach, a team of developers would deploy an application onto a physical server or virtual machine. Most of the time, that application server would be dedicated to a single mission critical application. Where a Virtual Machine provides hardware virtualization, a container provides OS virtualization. This means I can deploy and run multiple containers on a single physical machine or single virtual machine.
Each container gets it’s own user-mode space while all of the containers share the kernel. Since this hardware dependency was removed, you can easily redeploy your app as a container instance from one VM to another and should get the same experience. To try and do that with a classic application installed directly on a virtual machine application took much more time and effort.
Containers are based off of a container image. When your application is ready to evolve as a container, you first build that into an image and then deploy that image to a container registry. This is usually in the Cloud like Azure Cloud Registry. Free tools are available like Docker to help you package your solution into a docker image.
Azure Web App Basics
Once your image is available in Azure Container Registry or other container registry like Docker Hub, you can create your Azure Web App and based it off that docker image sitting in Azure Container Registry. The Azure Web App is really an Azure App Service. After creating an Azure Web App, it will appear in Azure Portal as an Azure App Service. Before building an Azure Web App resource, you’re required to build an Azure App Service Plan resource which provides compute resources to one or more Azure Web Apps. You have many options as far as configuring your Azure Web App further but I do want to highlight the continuous deployment feature.
Continuous Deployment is an option you enable within the Azure Web App and is basically a web hook that will be used by Azure Container Registry so that if you update an image used by an Azure Web App, it will be pushed to the Azure Web App and the new changes will appear.
In the video below, I will demo deploying a containerized Azure Web App with the following steps:
- Clone github repo containing the python web application
- Build Docker image and push to Azure Container Registry
- Provision Azure App Service Plan
- Provision Azure Web App based off docker image
- Enable Continuous Deployment and test
Feel free to follow along and you will need the following installed locally assuming you’re on a Windows 10 box:
Docker Desktop Download
Visual Studio Code Download
Git for Windows Download
Azure CLI Install