title: Azure web app for container - failed during startup - didn't respond to HTTP pings
body: <p>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. </p>
  
  <h3>The details:</h3>
  
  <ul>
  <li>azure web app for container with Linux OS on a Basic B1 machine.</li>
  <li>nodejs v12 LTS with express server listening on HTTPS port 443. Includes an HTTP 404 (Not Found) error handler.</li>
  <li>database db Mongodb Atlas on M0 Sandbox (free tier). Local and Azure IPs whitelisted.</li>
  <li>docker container using Dockerfile. no Kubernetes, no yml config file.</li>
  <li>docker image hosted on private Docker Hub repo, pulled by azure on build</li>
  </ul>
  
  <h3>Running locally on Windows 10 x64:</h3>
  
  <ul>
  <li><p>without docker: 
  <code>node app.js</code> 
  runs fine via <a href="https://localhost:443" rel="noreferrer">https://localhost:443</a> </p></li>
  <li><p>with docker: 
  <code>docker build -t myapp:latest .</code> then
  <code>docker run -p 49160:443 -d myapp:latest</code>
  runs fine via <a href="https://localhost:49160" rel="noreferrer">https://localhost:49160</a></p></li>
  </ul>
  
  <p>In both cases I get the expected output from my nodejs app:</p>
  
  <pre><code>Running in production on x64
  Express HTTPS server listening on port 443
  mongo :: connected to database mydb at mydb-tot7b.azure.mongodb.net
  </code></pre>
  
  <p>(obvously, myapp and mydb are not the actual names. Used here for convenience.)</p>
  
  <h3>Running in azure:</h3>
  
  <p>Under Configuration -> Application settings:</p>
  
  <pre><code>PORT=443
  WEBSITES_PORT=443
  DOCKER_ENABLE_CI=true
  </code></pre>
  
  <p>Pipeline set up pulling docker image <code>myrepo/myapp:latest</code> from private Docker Hub repo on build. Image is pulled correctly.
  <strong>Fails</strong> via <a href="https://myapp.azurewebsites.net/" rel="noreferrer">https://myapp.azurewebsites.net/</a> with <strong>error 503 Service Temporarily Unavailable</strong>.</p>
  
  <p>Azure log:</p>
  
  <pre><code>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.
  </code></pre>
  
  <p><strong>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?</strong><br>
  Do I need to make my HTTPS server explicitly respond to HTTP PING and if so, how do I do it?</p>
  
  <p>Dockerfile:</p>
  
  <pre><code>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" ]
  </code></pre>
  
  <p>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:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/58723980/docker-never-runs-on-azure-waiting-for-response-to-warmup-request-for-container">Docker never runs on Azure - Waiting for response to warmup request for container</a></li>
  <li><a href="https://stackoverflow.com/questions/55688600/azure-web-app-on-linux-error-container-didnt-respond-to-http-pings-on-portr">Azure Web App on Linux: &quot;Error: Container didn&#39;t respond to HTTP pings on port: 8080&quot; - when using: &quot;start&quot;: &quot;pm2 start server.js&quot;</a></li>
  <li><a href="https://stackoverflow.com/questions/48693878/how-do-you-expose-port-3000-using-an-azure-web-app-containerr">How do you expose port 3000 using an Azure Web App Container?</a></li>
  <li><a href="https://superuser.com/questions/1479521/i-cannot-create-a-node-js-web-app-to-be-deployed-on-azurer">https://superuser.com/questions/1479521/i-cannot-create-a-node-js-web-app-to-be-deployed-on-azurer</a></li>
  <li><a href="https://docs.microsoft.com/en-us/archive/blogs/waws/things-you-should-know-web-apps-and-linux#troubleshootingr" rel="noreferrer">https://docs.microsoft.com/en-us/archive/blogs/waws/things-you-should-know-web-apps-and-linux#troubleshootingr</a></li>
  <li><a href="https://docs.microsoft.com/en-us/azure/app-service/containers/app-service-linux-intro#troubleshootingr" rel="noreferrer">https://docs.microsoft.com/en-us/azure/app-service/containers/app-service-linux-intro#troubleshootingr</a></li>
  <li><a href="https://docs.microsoft.com/en-us/azure/app-service/containers/configure-language-nodejsr" rel="noreferrer">https://docs.microsoft.com/en-us/azure/app-service/containers/configure-language-nodejsr</a></li>
  <li><a href="https://github.com/MicrosoftDocs/azure-docs/issues/46401r" rel="noreferrer">https://github.com/MicrosoftDocs/azure-docs/issues/46401r</a></li>
  <li><a href="https://github.com/MicrosoftDocs/azure-docs/issues/34451r" rel="noreferrer">https://github.com/MicrosoftDocs/azure-docs/issues/34451r</a></li>
  <li><a href="https://omgdebugging.com/2017/12/22/azure-web-app-for-container-failing-site-start/r" rel="noreferrer">https://omgdebugging.com/2017/12/22/azure-web-app-for-container-failing-site-start/r</a></li>
  <li><a href="https://devops.stackexchange.com/questions/4543/how-to-debug-a-docker-on-web-app-for-containers-in-azure-which-does-not-startr">https://devops.stackexchange.com/questions/4543/how-to-debug-a-docker-on-web-app-for-containers-in-azure-which-does-not-startr</a></li>
  <li><a href="https://docs.microsoft.com/en-us/azure/app-service/containers/app-service-linux-faq#custom-containersr" rel="noreferrer">https://docs.microsoft.com/en-us/azure/app-service/containers/app-service-linux-faq#custom-containersr</a></li>
  <li><a href="https://stackoverflow.com/questions/58495639/running-a-docker-container-in-azure-web-app-didnt-respond-to-http-pings-on-porr">Running a docker container in Azure web app: didn&#39;t respond to HTTP pings on port</a></li>
  <li><a href="https://stackoverflow.com/questions/52850254/docker-container-fails-to-start-in-an-azure-app-servicer">Docker Container fails to start in an Azure App Service</a></li>
  <li><a href="https://docs.microsoft.com/en-us/azure/container-instances/container-instances-troubleshootingr" rel="noreferrer">https://docs.microsoft.com/en-us/azure/container-instances/container-instances-troubleshootingr</a></li>
  <li><a href="https://serverfault.com/questions/1003418/azure-docker-app-error-site-did-not-start-within-expected-time-limit-and-cor">https://serverfault.com/questions/1003418/azure-docker-app-error-site-did-not-start-within-expected-time-limit-and-cor</a></li>
  <li><a href="https://medium.com/@sergiibielskyi/azure-event-hub-listener-in-the-container-dd6f8d053814r" rel="noreferrer">https://medium.com/@sergiibielskyi/azure-event-hub-listener-in-the-container-dd6f8d053814r</a></li>
  </ul>