Deploying Web Application On Azure App Service Through Docker

Azure provides a PAAS service to host your application. It provides flexibility and scalability and takes the burden of server management from the user but it sometimes can become a headache to deploy your application on app service, especially when you're using a technology stack other than .Net. For this, we can use docker based deployment so your application works perfectly on the server too. 
To deploy applications on the Azure App Service through Docker we need the following steps,

Step 1 - Create a Docker File
  • Create a Docker file through Docker VS Code extension. Go to VS code marketspace and install Docker extension
  • Click on View -> Command Palette-> Docker: Add Docker file to workspace
  • Select technology, OS
  • Try to create the Docker file in the same directory which contains your code.
Step 2 - Create Docker Image
To create Docker image through Docker file run the following command
  1. docker build -t imagename:tag .  
-t means we want to run the command in the attached form so we can see the logs
Imagename:tag tag is to maintain the different image version
define that run the Docker file in the current directory
Step 3 - Create Container to test your application
To create the Docker container from the Docker image run the following command
  1. docker run --publish 8000:8000 -t --name containerName imagename:tag  
--publish hostport:guestport so, we can attach our container port to our guest OS port
Now test your application by sending a request to 8000 port of your guestip:8000 to see if your application is working in container or not.
Step 4 - Push Docker Image to Azure container registry 
  • We need to first login into the Azure container registry by running the following commands

    AZ logging -> to login to azure cli

  • Now go visual studio extension and click on Docker extension
  • Select the image, right-click on it and add tag
  • Add tag {container registry name / image name)
  • Right-click on the image and push it
Step 5 - Deploy the Image to APP service
  • Select the Docker extension and select the container registry on which the application is deployed
  • Right Click on the image you want to deploy
  • Select the option “deploy to app service”
  • Enter the name of the app service and resource group