Azure 应用服务响应 Web 应用(Linux Web 应用)容器无法启动

Posted

技术标签:

【中文标题】Azure 应用服务响应 Web 应用(Linux Web 应用)容器无法启动【英文标题】:Azure app service react web app (linux web application) container fails to start 【发布时间】:2022-01-19 13:26:37 【问题描述】:

我在 Azure 应用服务 (web) 上配置了一个 react web 应用程序,并且运行良好,直到今天。早上,应用程序自行停止,尽管尝试了一切,但它没有再次运行。我什至尝试再次删除并重新创建应用服务计划和网络应用,但即使这样也无济于事。最初,该应用程序没有使用 VS Code 进行部署,它一直在抛出“java-script heap”错误。

最后,我们很幸运,能够成功部署,但现在应用程序无法运行,因为底层容器无法启动。 以下是容器的日志;

Starting Live Log Stream ---
2021-12-16T12:00:29.002Z INFO - Waiting for response to warmup request for container sitename_0_7fa82e24. Elapsed time = 180.8362096 sec
2021-12-16T11:57:27.548978985Z
2021-12-16T11:57:27.549013487Z / \
2021-12-16T11:57:27.549019288Z / /\ _ / | _ _/ \
2021-12-16T11:57:27.549023888Z / | \/ /| | /| | \/\ /
2021-12-16T11:57:27.549028088Z _| / _/ || ___ >
2021-12-16T11:57:27.549032789Z \/ \/ \/
2021-12-16T11:57:27.549036789Z A P P S E R V I C E O N L I N U X
2021-12-16T11:57:27.549040489Z
2021-12-16T11:57:27.549044189Z Documentation: http://aka.ms/webapp-linux
2021-12-16T11:57:27.549047790Z NodeJS quickstart: https://aka.ms/node-qs
2021-12-16T11:57:27.549051590Z NodeJS Version : v12.22.4
2021-12-16T11:57:27.549055190Z Note: Any data outside '/home' is not persisted
2021-12-16T11:57:27.549058991Z
2021-12-16T11:57:27.742608366Z Found build manifest file at '/home/site/wwwroot/oryx-manifest.toml'. Deserializing it...
2021-12-16T11:57:27.742664370Z Build Operation ID: |GCRCup2q1gg=.64a07be1_
2021-12-16T11:57:28.577072371Z Environment Variables for Application Insight's IPA Codeless Configuration exists..
2021-12-16T11:57:28.974502540Z Writing output script to '/opt/startup/startup.sh'
2021-12-16T11:57:29.384091441Z Running #!/bin/sh
2021-12-16T11:57:29.385286422Z
2021-12-16T11:57:29.385306924Z # Enter the source directory to make sure the script runs where the user expects
2021-12-16T11:57:29.386212086Z cd "/home/site/wwwroot"
2021-12-16T11:57:29.386228887Z
2021-12-16T11:57:29.386331294Z export NODE_PATH=/usr/local/lib/node_modules:$NODE_PATH
2021-12-16T11:57:29.386340394Z if [ -z "$PORT" ]; then
2021-12-16T11:57:29.386577211Z export PORT=8080
2021-12-16T11:57:29.386590312Z fi
2021-12-16T11:57:29.386807026Z
2021-12-16T11:57:29.386818427Z echo Found tar.gz based node_modules.
2021-12-16T11:57:29.387013941Z extractionCommand="tar -xzf node_modules.tar.gz -C /node_modules"
2021-12-16T11:57:29.387025341Z echo "Removing existing modules directory from root..."
2021-12-16T11:57:29.388049411Z rm -fr /node_modules
2021-12-16T11:57:29.388066012Z mkdir -p /node_modules
2021-12-16T11:57:29.388071313Z echo Extracting modules...
2021-12-16T11:57:29.388076013Z $extractionCommand
2021-12-16T11:57:29.388080713Z export NODE_PATH="/node_modules":$NODE_PATH
2021-12-16T11:57:29.388085514Z export PATH=/node_modules/.bin:$PATH
2021-12-16T11:57:29.388090214Z if [ -d node_modules ]; then
2021-12-16T11:57:29.388094814Z mv -f node_modules _del_node_modules || true
2021-12-16T11:57:29.388100915Z fi
2021-12-16T11:57:29.389438106Z
2021-12-16T11:57:29.389452407Z if [ -d /node_modules ]; then
2021-12-16T11:57:29.389457308Z ln -sfn /node_modules ./node_modules
2021-12-16T11:57:29.389461508Z fi
2021-12-16T11:57:29.389465608Z
2021-12-16T11:57:29.389469608Z echo "Done."
2021-12-16T11:57:29.389473809Z npm start
2021-12-16T11:57:29.394928782Z Found tar.gz based node_modules.
2021-12-16T11:57:29.395115194Z Removing existing modules directory from root...
2021-12-16T11:57:29.404384428Z Extracting modules...
2021-12-16T11:57:37.111103337Z Done.
2021-12-16T11:57:38.225542111Z npm info it worked if it ends with ok
2021-12-16T11:57:38.227305632Z npm info using npm@6.14.14
2021-12-16T11:57:38.228125888Z npm info using node@v12.22.4
2021-12-16T11:57:47.080897321Z npm info lifecycle ckc@0.1.0~prestart: ckc@0.1.0
2021-12-16T11:57:47.085197514Z npm info lifecycle ckc@0.1.0~start: ckc@0.1.0
2021-12-16T11:57:47.095371109Z
2021-12-16T11:57:47.095400911Z > ckc@0.1.0 start /home/site/wwwroot
2021-12-16T11:57:47.095407612Z > react-scripts start
2021-12-16T11:57:47.095412812Z
2021-12-16T11:57:53.418958010Z [34mℹ[39m [90m「wds」[39m: Project is running at http://0.0.0.0:8080/
2021-12-16T11:57:53.420069286Z [34mℹ[39m [90m「wds」[39m: webpack output is served from
2021-12-16T11:57:53.420771034Z [34mℹ[39m [90m「wds」[39m: Content not from webpack is served from /home/site/wwwroot/public
2021-12-16T11:57:53.421431479Z [34mℹ[39m [90m「wds」[39m: 404s will fallback to /
2021-12-16T11:57:53.422214432Z Starting the development server...
2021-12-16T11:57:53.422231133Z
2021-12-16T12:01:30.077Z ERROR - Container sitename_0_7fa82e24 for site sitename did not start within expected time limit. Elapsed time = 241.9112726 sec
2021-12-16T12:01:30.114Z ERROR - Container sitename_0_7fa82e24 didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging.
2021-12-16T12:01:30.125Z INFO - Stopping site sitename because it failed during startup.
2021-12-16T12:01:31.069Z INFO - Starting container for site
2021-12-16T12:01:31.070Z INFO - docker run -d -p 8080:8080 --name sitename_0_b6f4d68b -e WEBSITE_SITE_NAME=sitename -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=sitename.azurewebsites.net -e WEBSITE_INSTANCE_ID=f4f616335a5d3f9996fa924d731ee521d71d70773936a71ee1c390d5d8489465 -e NODE_OPTIONS=--require /agents/node/build/src/Loader.js appsvc/node:12-lts_20210810.1
2021-12-16T12:01:31.071Z INFO - Logging is not enabled for this container.Please use https://aka.ms/linux-diagnostics to enable logging to see container logs here.
2021-12-16T12:01:36.141Z INFO - Initiating warmup request to container sitename_0_b6f4d68b for site sitename
2021-12-16T12:01:52.650Z INFO - Waiting for response to warmup request for container sitename_0_b6f4d68b. Elapsed time = 16.5091765 sec

有人可以帮忙吗!

【问题讨论】:

【参考方案1】:

容器站点名_0_7fa82e24 未响应端口上的 HTTP ping:> 8080,站点启动失败。查看容器日志进行调试。

Azure Web 应用程序只支持 80 和 443 端口,所以请检查程序中是否只启用了一个端口。比如配置port: process.env.PORT || 3000。 但您可以使用WEBSITES_PORT 指向其他端口。变量 "PORT" 似乎已过时,可能与 WEBSITES_PORT 冲突。 所以我的建议是删除"PORT"。直接使用WEBSITE_PORT指定需要的端口,比如8080。顺便说一下,端口必须是容器暴露的。 如果您的容器侦听另一个端口(例如:8081),只需将 WEBSITES_PORT 应用程序设置设置为该端口号。应用服务将侦听端口 80 并将流量转发到您的容器端口。

将 server.js 文件中的代码更改为以下代码:

const port = process.env.port || 8080;

在您的构建任务中将环境变量NODE_OPTIONS 设置为--max_old_space_size=16384

“java-script heap”错误。

由于旧空间的默认限制,node.js 无法分配更多内存,一个快速的解决方法是增加以 MB 为单位的堆参数,如下所示:

在应用服务 Linux 上,我们使用 PM2,因此您可以通过门户中的启动文件选项添加参数或在 JSON 文件中指定参数。结帐Node.js — Increase the Memory Limit for Your Process了解更多详情。

【讨论】:

@Akash Lomas - 如果我的回答对您有帮助,您可以接受它作为答案(单击答案旁边的复选标记,将其从灰色切换为已填充。)。这对其他社区成员可能是有益的。谢谢

以上是关于Azure 应用服务响应 Web 应用(Linux Web 应用)容器无法启动的主要内容,如果未能解决你的问题,请参考以下文章

在 Chrome 中托管在 Azure 中的 ASP.NET Core Web 应用程序上的异常 HTTP 响应

Azure 长响应时间瓶颈?

如何防止 HttpWebRequest 长时间响应超时 Azure Web App

通过 Azure Devops 将 .Net Core 3.1 Web 应用程序部署到 Azure Linux Web 服务时出错

Azure Web App 上的高响应时间 [关闭]

Azure-如何排查应用程序网关返回 HTTP Code 502 或客户端得到应用程序网关响应慢的问题