I'm running into an annoying issue where my containerized app runs fine locally, but fails when deployed to azure, despite the ports being exposed properly.
The details:
- azure web app for container with Linux OS on a Basic B1 machine.
- nodejs v12 LTS with express server listening on HTTPS port 443. Includes an HTTP 404 (Not Found) error handler.
- database db Mongodb Atlas on M0 Sandbox (free tier). Local and Azure IPs whitelisted.
- docker container using Dockerfile. no Kubernetes, no yml config file.
- docker image hosted on private Docker Hub repo, pulled by azure on build
Running locally on Windows 10 x64:
without docker:
node app.js
runs fine via https://localhost:443with docker:
docker build -t myapp:latest .
thendocker run -p 49160:443 -d myapp:latest
runs fine via https://localhost:49160
In both cases I get the expected output from my nodejs app:
Running in production on x64Express HTTPS server listening on port 443mongo :: connected to database mydb at mydb-tot7b.azure.mongodb.net
(obvously, myapp and mydb are not the actual names. Used here for convenience.)
Running in azure:
Under Configuration -> Application settings:
PORT=443WEBSITES_PORT=443DOCKER_ENABLE_CI=true
Pipeline set up pulling docker image myrepo/myapp:latest
from private Docker Hub repo on build. Image is pulled correctly.Fails via https://myapp.azurewebsites.net/ with error 503 Service Temporarily Unavailable.
Azure log:
2020-04-10 18:02:21.040 INFO - Pulling image: myrepo/myapp:latest2020-04-10 18:02:22.128 INFO - latest Pulling from myrepo/myapp2020-04-10 18:02:22.129 INFO - Digest: sha256:982[...]2020-04-10 18:02:22.129 INFO - Status: Image is up to date for myrepo/myapp:latest2020-04-10 18:02:22.131 INFO - Pull Image successful, Time taken: 0 Minutes and 1 Seconds2020-04-10 18:02:22.143 INFO - Starting container for site2020-04-10 18:02:22.144 INFO - docker run -d -p 7909:443 --name myapp_0_138f197c -e PORT=80 -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITES_PORT=443 -e WEBSITE_SITE_NAME=myapp -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=myapp.azurewebsites.net -e WEBSITE_INSTANCE_ID=6fc3[...] myrepo/myapp:latest2020-04-10 18:02:22.144 INFO - Logging is not enabled for this container.Please use https://aka.ms/linux-diagnostics to enable logging to see container logs here.2020-04-10 18:02:23.473 INFO - Initiating warmup request to container myapp_0_138f197c for site myapp2020-04-10 18:02:45.304 INFO - Waiting for response to warmup request for container myapp_0_138f197c. Elapsed time = 21.8308149 sec[...]2020-04-10 18:06:08.252 INFO - Waiting for response to warmup request for container myapp_0_138f197c. Elapsed time = 224.7791547 sec2020-04-10T18:02:24.893958779Z Running in production on x642020-04-10T18:02:26.275376640Z Express HTTPS server listening on port 802020-04-10T18:02:26.601261213Z mongo :: connected to database mydb at mydb-tot7b.azure.mongodb.net2020-04-10 18:06:14.346 ERROR - Container myapp_0_138f197c for site myapp did not start within expected time limit. Elapsed time = 230.8732099 sec2020-04-10 18:06:14.365 ERROR - Container myapp_0_138f197c didn't respond to HTTP pings on port: 443, failing site start. See container logs for debugging.2020-04-10 18:06:14.427 INFO - Stoping site myapp because it failed during startup.
Why the containerized app seems to start correctly, as seen in the azure log, but the container fails to respond to HTTP ping on 443, which is exposed both in dockerfile and in azure with PORT and WEBSITES_PORT?
Do I need to make my HTTPS server explicitly respond to HTTP PING and if so, how do I do it?
Dockerfile:
FROM node:12WORKDIR /usr/src/myappCOPY package*.json ./ARG NODE_ENV=productionENV NODE_ENV=${NODE_ENV}RUN npm installCOPY . .EXPOSE 443CMD [ "node", "app.js" ]
This issue might be considered a duplicate, but I provide a lot more relevant information, compared to most of the issues below. Also, I spent significant time in troubleshooting and none of these relevant resources seemed to help:
- Docker never runs on Azure - Waiting for response to warmup request for container
- Azure Web App on Linux: "Error: Container didn't respond to HTTP pings on port: 8080" - when using: "start": "pm2 start server.js"
- How do you expose port 3000 using an Azure Web App Container?
- https://superuser.com/questions/1479521/i-cannot-create-a-node-js-web-app-to-be-deployed-on-azurer
- https://learn.microsoft.com/en-us/archive/blogs/waws/things-you-should-know-web-apps-and-linux#troubleshootingr
- https://learn.microsoft.com/en-us/azure/app-service/containers/app-service-linux-intro#troubleshootingr
- https://learn.microsoft.com/en-us/azure/app-service/containers/configure-language-nodejsr
- https://github.com/MicrosoftDocs/azure-docs/issues/46401r
- https://github.com/MicrosoftDocs/azure-docs/issues/34451r
- https://omgdebugging.com/2017/12/22/azure-web-app-for-container-failing-site-start/r
- https://devops.stackexchange.com/questions/4543/how-to-debug-a-docker-on-web-app-for-containers-in-azure-which-does-not-startr
- https://learn.microsoft.com/en-us/azure/app-service/containers/app-service-linux-faq#custom-containersr
- Running a docker container in Azure web app: didn't respond to HTTP pings on port
- Docker Container fails to start in an Azure App Service
- https://learn.microsoft.com/en-us/azure/container-instances/container-instances-troubleshootingr
- https://serverfault.com/questions/1003418/azure-docker-app-error-site-did-not-start-within-expected-time-limit-and-cor
- https://medium.com/@sergiibielskyi/azure-event-hub-listener-in-the-container-dd6f8d053814r