【问题标题】:Azure Deployment Failure - Container didn't respond to HTTP pings on port: 8080, failing site startAzure 部署失败 - 容器未响应端口:8080 上的 HTTP ping,站点启动失败
【发布时间】:2021-02-17 09:54:34
【问题描述】:

我正在 Azure 应用服务(插入我的 BitBucket 存储库)上部署一个使用 NodeJS、Express 和 React 的 Web 应用程序,但我没有找到成功。部署失败,或者它声称它成功,但该站点无法访问并且一直超时。当我在 Azure 诊断中检查 Docker 日志时,我注意到以下内容:

2021-02-14T13:41:53.578Z INFO  - Initiating warmup request to container mcm-app_0_543ad0c3 for site mcm-app

在读取Waiting for response to warmup request for container mcm-app_0_543ad0c3 的几条日志之后,我得到以下信息:

2021-02-14T13:45:44.205Z ERROR - Container mcm-app_0_543ad0c3 for site mcm-app did not start within expected time limit. Elapsed time = 230.6269687 sec
2021-02-14T13:45:44.236Z ERROR - Container mcm-app_0_543ad0c3 didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging.
2021-02-14T13:45:44.299Z INFO  - Stopping site mcm-app because it failed during startup.

这就是我的 Express 后端的 server.js 文件的样子:

var express = require("express");
var cors = require("cors");
var app = express();
var path = require("path");

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

// Enable CORS and handle JSON requests
app.use(cors());
app.use(express.json());

app.post("/", function (req, res, next) {
  // console.log(req.body);
  res.json({ msg: "This is CORS-enabled for all origins!" });
});

// Set router for email notifications
const mailRouter = require("./routers/mail");
const readerRouter = require("./routers/reader");
const notificationsRouter = require("./routers/booking-notifications");
app.use("/email", mailRouter);
app.use("/reader", readerRouter);
app.use("/notifications", notificationsRouter);


app.use(express.static("./mcm-app/build"));
app.get("*", (req, res) => {
  res.sendFile(path.join(__dirname, "mcm-app", "build", "index.html"));
});

app.listen(port, () => {
  // console.log(`Server is running on port: ${port}`);
});

顺便说一句,我客户的package.json 不包含任何proxy 命令。我删除了它。无论如何都会出现错误。

另外,根据一些建议,我已尝试在 Azure 配置中将 WEBSITES_PORT 设置为 8080。但到目前为止没有任何效果。

如果我能得到一些详细的指导来解决这个问题,我将不胜感激。我没有使用 .yml 文件,以防万一。

【问题讨论】:

  • 在你的代码中,我在你的代码中看到了process.env.PORT,所以你的webapp应用实际上使用了端口80 or 443,而你的WEBSITES_PORT是无效的。因为only one port can be exposed in the container,我认为8080无效。
  • 你尝试将const port = process.env.PORT || 8080;修改为const port = 8080;,然后按照截图中的cli命令进行设置。
  • 在 azure web app 中,它只支持 80/443 端口。但是你可以像 pic 一样设置它,当你 delpoy 你的 webapp 时,它总是会路由到 8080 端口。如果我的评论对你有用,请告诉我。
  • @JasonPan 感谢您的建议。在您发布答案之前,我实际上是使用 Docker Compose 来部署我的测试应用程序。所以现在一切都很好:stackoverflow.com/a/66213919/1536240
  • 您可以在下方发布您的答案,并与大家分享您的解决方案,这将帮助很多人。我以前看过很多类似的帖子。 ^-^

标签: node.js azure express azure-devops azure-web-app-service


【解决方案1】:

我发现 Isaac 已经通过以下解决方案设法解决了这个问题。

在 docker-compose.yml 文件中添加 tty: true 。此外,为了使应用程序中的前端-后端交互按预期工作,请将客户端 package.json 中的代理命令更改为以下内容:

"proxy": "http://backend:5000"

并将 docker-compose.yml 中的链接命令更改为:

  - "backend:be"

在这里分享答案,以帮助将来可能遇到相同问题的其他人。

【讨论】:

猜你喜欢
  • 2021-08-04
  • 1970-01-01
  • 1970-01-01
  • 2020-09-16
  • 1970-01-01
  • 1970-01-01
  • 2020-02-17
  • 2016-01-16
  • 2011-07-15
相关资源
最近更新 更多