Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure web app for container - failed during startup - didn't respond to HTTP pings

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:443

  • with docker: docker build -t myapp:latest . then docker 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 x64
Express HTTPS server listening on port 443
mongo :: 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=443
WEBSITES_PORT=443
DOCKER_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:latest
2020-04-10 18:02:22.128 INFO  - latest Pulling from myrepo/myapp
2020-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:latest
2020-04-10 18:02:22.131 INFO  - Pull Image successful, Time taken: 0 Minutes and 1 Seconds
2020-04-10 18:02:22.143 INFO  - Starting container for site
2020-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:latest
2020-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 myapp
2020-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 sec
2020-04-10T18:02:24.893958779Z Running in production on x64
2020-04-10T18:02:26.275376640Z Express HTTPS server listening on port 80
2020-04-10T18:02:26.601261213Z mongo :: connected to database mydb at mydb-tot7b.azure.mongodb.net
2020-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 sec
2020-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:12

WORKDIR /usr/src/myapp

COPY package*.json ./

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

RUN npm install

COPY . .

EXPOSE 443
CMD [ "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://docs.microsoft.com/en-us/archive/blogs/waws/things-you-should-know-web-apps-and-linux#troubleshootingr
  • https://docs.microsoft.com/en-us/azure/app-service/containers/app-service-linux-intro#troubleshootingr
  • https://docs.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://docs.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://docs.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
like image 516
Mike Avatar asked Apr 12 '20 10:04

Mike


People also ask

How do I specify port in my Linux container?

How do I specify port in my Linux container? If you select a language/framework version for a Linux app, a predefined container is selected for you. To point your app code to the right port, use the PORT environment variable. You have full control over the container.


2 Answers

When enforcing HTTPS at the App Service level, TLS termination will happen and traffic will be routed to your container port so there's no need to enforce TLS from your container.

If your container listens on another port (ex: 8081), simply set the WEBSITES_PORT application setting to that port number. App Service will listen on port 80 and forward traffic to your container port.

like image 62
CSharpRocks Avatar answered Sep 21 '22 15:09

CSharpRocks


My own app had been doing app.UseHttpsRedirection() in Startup.Configure. That was the cause of this error for me. As soon as I stopped doing that, the problem went away.

like image 23
David Avatar answered Sep 21 '22 15:09

David