Intro
A great feature of Azure App Service is the ability to create a containerized Web Application off a docker container. When an Azure App Service is created, one can select a container and proceed to pick an image. That image can be from a variety of locations including Azure Container Registry.
I ran into a problem that took me much longer to figure out than it should have. I built a simple python web application built on the flask web framework. My next post I will include a link to a Youtube video where I’ll walk through the entire working process. What I found is that I kept creating an App Service resource based on my image and launching the site in a browser would just hang and the site would never render.
After experiencing the site stuck on loading, I went into Azure Portal, App Service, and selected Container Settings. Within logs window, you will see something like this:
Container Log
2020-11-21T21:26:27.821Z INFO – docker run -d -p 4614:80 –name brokenwebapp_0_f08b6c30 -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=brokenwebapp -e WEBSITE_AUTH_ENABLED=False -e PORT=80 -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=brokenwebapp.azurewebsites.net -e WEBSITE_INSTANCE_ID=0ad77158b contoso.azurecr.io/initialwa:latest
2020-11-21T21:26:27.821Z INFO – Logging is not enabled for this container.
Please use https://aka.ms/linux-diagnostics to enable logging to see container logs here.
2020-11-21T21:26:38.417Z INFO – Initiating warmup request to container brokenwebapp_0_f08b6c30 for site brokenwebapp
2020-11-21T21:26:53.844Z INFO – Waiting for response to warmup request for container brokenwebapp_0_f08b6c30. Elapsed time = 15.4271477 sec
2020-11-21T21:27:09.535Z INFO – Waiting for response to warmup request for container brokenwebapp_0_f08b6c30. Elapsed time = 31.1182007 sec
2020-11-21T21:27:24.989Z INFO – Waiting for response to warmup request for container brokenwebapp_0_f08b6c30. Elapsed time = 46.5715522 sec
2020-11-21T21:27:40.566Z INFO – Waiting for response to warmup request for container brokenwebapp_0_f08b6c30. Elapsed time = 62.1487043 sec
2020-11-21T21:27:55.685Z INFO – Waiting for response to warmup request for container brokenwebapp_0_f08b6c30. Elapsed time = 77.2682134 sec
My app service is name is brokenwebapp so this is why you see that in the message above. It will eventually timeout but then attempt to load the container again and will rinse and repeat this process so you just see this message above.
If you experience a similar issue, the first place you should go is your solution. In my solution, I see the following:
Python Web App Solution
My solution is a simple python web application running on the Flask web framework. The main files for building the image include the DockerFile and the App.Py file.
DockerFile
app.py
How to Fix
My problem is that I didn’t specify a port to listen on. When a container is spun up in Azure App Service, it expects the container to be listening on port 80. I know this because in the container logs above I see the attempt to run a docker container by Azure:
docker run -d -p 4614:80
The Docker run command is used to instantiate a container off an image, when the -p port:port is specified, the first port represents the port of the host machine and the second port represents the port of the container. So in the above example, the host is receiving web requests on port 4614 and the container listens on port 80. The fix is to update my python app to ensure it’s listening on port 80. After updating, my App.Py looks like
Externally, Microsoft will accept requests on port 80 and 443 by default for an Azure App Service Web App. I assume they have some port mapping magic behind the scenes so that it maps to the port of the host machine and then that host machine maps to the container port of 80.
Thank You,
Russ Maxwell