Docker Blog Series Part 7– Deploy Azure Web App On Containers
Container services are encapsulated, individually deployable components that run as isolated instances on the same kernel to take advantage of virtualization that an operating system provides. Thus, each application and its runtime, dependencies, and system libraries run inside a container with full, private access to the container's own isolated view of operating system constructs.
Azure has various services to orchestrate containers like Azure Service Fabric, Azure Container Service, Azure Kubernetes Service and ACI. In this blog post, we will see how to deploy containers on Web Apps.
Step 1: Create a ASPNET Core Web Application using Visual Studio.
Step 2: Select Web Application template. DO NOT check “Enable Docker Support”
Step 3: Once the application is loaded in Visual Studio add a Dockerfile to the root of the project.
Step 4. Open the Dockerfile in Visual Studio and add the following steps in the Dockerfile and Save the Dockerfile.
FROM microsoft/aspnetcore:latest
WORKDIR dockerdemo
ADD ./WebApp .
ENTRYPOINT ["dotnet","bin/Debug/netcoreapp2.0/publish/WebApp.dll"]
EXPOSE 8086
ENV ASPNETCORE_URLS https://0.0.0.0:8086
Step 5. Open Powershell in Admin Mode and browse to the project folder.
Step 6. Execute Docker build command to build image from the Dockerfile. Include tag name in the build command as shown below.
docker build . -t monuacr.azurecr.io/webapp:1
Step 7. Execute Docker run command to create the container using the image previously created as shown below
docker run monuacr.azurecr.io/webapp:1
Step 8. Inspect the IP address on which the container is running by executing network inspector nat command.
Step 9. Open the web browser and navigate to the IP address and you will see the ASP.Net core application running.
Step 10. Publish the image to Azure Container Registry.
docker push monuacr.azurecr.io/webapp:1
Azure Web App on Containers
Now we will deploy our container image which we pushed to the Azure Container Registry to Azure Web App as a container deployment. We can easily deploy and run containerized web apps that scale with business needs. Currently we can deploy Azure Web apps on Linux Containers.
Step 11. Go to the Azure Portal and Navigate to the Container registry we pushed the image to.
Step 12. Click on Repositories.
Step 13. Now Click on the image we pushed to the Repository.
Step 14. Now Click on the Deploy to Web App link. This will enable us to deploy the image to Azure Web App.
Step 15. Fill in the required values for the web app and click on Create.
Step 16. Azure Web App is up and running using the Docker image on Linux Container. Navigate to the Web App on the Portal.
As you saw, we can deploy Azure web apps on containers and avail all the PAAS benefits of the Azure Web App Platform along with being portable by using Containers.
For more information, check out this article.
https://azure.microsoft.com/en-us/services/app-service/containers/