容器的Azure Web应用-启动期间失败-未响应HTTP ping [英] Azure web app for container - failed during startup - didn't respond to HTTP pings

查看:110
本文介绍了容器的Azure Web应用-启动期间失败-未响应HTTP ping的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个令人烦恼的问题,我的容器化应用在本地运行良好,但是尽管端口正确暴露,但部署为天蓝色时却失败了.

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.

  • Basic B1机器上具有Linux操作系统的容器的Azure Web应用程序.
  • 带有高速服务器在HTTPS端口443上侦听的nodejs v12 LTS.包括HTTP 404(未找到)错误处理程序.
  • M1沙盒上的
  • 数据库db Mongodb Atlas(免费).本地和Azure IP列入白名单.
  • 使用Dockerfile的docker容器.没有Kubernetes,没有yml配置文件.
  • 托管在私有Docker Hub仓库上的docker映像,由天蓝色在构建过程中拉取

使用docker: docker build -t myapp:latest.然后 docker run -p 49160:443 -d myapp:latest 通过 https://localhost:49160

with docker: docker build -t myapp:latest . then docker run -p 49160:443 -d myapp:latest runs fine via https://localhost:49160

在两种情况下,我都从我的nodejs应用程序获得了预期的输出:

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

(很明显,myapp和mydb不是实际名称.为方便起见,在此使用.)

(obvously, myapp and mydb are not the actual names. Used here for convenience.)

正在配置->应用程序设置:

Under Configuration -> Application settings:

PORT=443
WEBSITES_PORT=443
DOCKER_ENABLE_CI=true

管道在建立时从私有Docker Hub存储库中提取docker映像 myrepo/myapp:latest .图像被正确拉出.通过 https://myapp.azurewebsites.net/ 失败,出现错误503服务暂时不可用.

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.

天蓝色日志:

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.

为什么容器化的应用程序似乎可以正常启动(如azure日志中所示),但是容器无法响应443上的HTTP ping,而ping在dockerfile和PORT和WEBSITES_PORT中都公开了?强>
我是否需要使我的HTTPS服务器显式响应HTTP PING?如果是,该怎么做?

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:

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

推荐答案

在App Service级别强制执行HTTPS时,将终止TLS,并将流量路由到您的容器端口,因此无需从您的容器中强制执行TLS.

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.

如果您的容器侦听另一个端口(例如:8081),只需将 WEBSITES_PORT 应用程序设置设置为该端口号.App Service将侦听端口80并将流量转发到您的容器端口.

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.

这篇关于容器的Azure Web应用-启动期间失败-未响应HTTP ping的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆