In my previous article in the series we learned how we host our custom image on dockers hub registry. In this blog we will look into how we can host it to Azure WebApp for containers.
Azure WebApp for containers is part of App service Plan and allows us to run containerized applications to host on windows and Linux. You can pull container images from Azure Container Registry, Docker Hub or a private Docker repository. This provides us flexibility that we can run our own custom images with custom logic and frameworks on WebApps. There is an preview feature available, that is deployment of multiple containers using docker compose on Linux. In the next article we will look into how we can run application that will use multiple containers using Azure Container Registry.
Just a note to remember that there are also other services in Azure to host containers like Azure Container Instances and powerful Azure Kubernetes services (AKS) but today's article is about WebApp for containers for the following reasons:
- Teams (developers) are already more familiar with Azure web apps environments.
- Already utilizing built-in features of App service plan (load balancing/Auto scale etc.).
- DevOps CI/CD deployments already in place (few modifications might needed).
- Light weight Container/Containers and need simple orchestration.
- Need tighter isolation of not only code but packages, runtime framework, tooling etc.
- Demo or POC applications on low cost or shared app plans.
- Wonderful for testing as Sandbox or UAT environments for developers.
- Wonderful debugging experience both for Visual studio (built-it) or Visual Studio Code.
- Can be many others … (please share your thoughts in comments).
Now let’s jump into creating the WebApp for containers and required components through Azure CLI and using bash. If you are unsure how to use Azure CLI please follow this.
Create WebApp for Containers
1. Create resource within region, for example West Europe.
az group create --name Dynamic365RG --location westeurope --tags "Demo=WAC"
2. Create a Linux app plan.
az appservice plan create -n linuixappplan -g Dynamic365RG --is-linux
3. Now we create a webapp to run our public image from Docker hub repository.
az webapp create -n devopswebapp -g Dynamic365RG -p linuixappplan -i yesadahmed/azuredevopsapipat:version1.0
Please note yesadahmed/azuredevopsapipat: version1.0 is my custom image on my docker's hub registry. Please feel free you use your own or any image.
Now everything is up and running under resource Dynamic365RG in azure portal.
Now if we go back to our WebApp hits its URL in azure portal, we will have our .Net core 3.1 WebAPI running on container. Note the URL hosted on azure webapp.
Now we can also see the logs in the container’s setting blade (as shown above).
Handle automatic updates(pushes) to WebApp:
Let's enable (turn on) continuous deployment button on webapp container settings blade to receive automatic updates on our azure WebApp. Means whenever we push(git) any change to our actual container in docker’s hub repository they are automatically applied to our WebApp. Isn't amazing, think if we have product and we are deploying its feature to clients so rapidly.
Now copy the webhook URL from container’s setting blade and paste into the dockers hub webhooks.
That’s it, now whenever there is change in our container in dockers then our WebApp in azure will be updated accordingly and show the results.
Great, isn’t with in no time we have our application running on single container. Another cool benefit is that the WebApp KUDU SCM site (developers) runs in separated container from the main WebApp. More info here.
Debugging Containers
Worth to note, that there is a great built-in support for debugging code in containers in visual studio and as well as in visual studio code. You can refer to my previous article and also here are some links to get started:
https://docs.microsoft.com/en-us/visualstudio/containers/edit-and-refresh?view=vs-2019
https://code.visualstudio.com/docs/containers/debug-common
https://code.visualstudio.com/docs/containers/debug-netcore
In the next article we will look into how we can use Azure Container Registry to host our custom images instead of Docker’s hub repository.
Happy Coding!