Azure 部署失败 - 容器未响应端口 8080 上的 HTTP ping,站点启动失败



我正在部署一个使用Azure应用服务上的NodeJS, Express和React的web应用程序(插入到我的BitBucket repo),我没有找到成功。要么部署失败,要么它声称部署成功,但站点无法访问并一直超时。当我检查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文件,如果有帮助的话。

我发现Isaac已经设法用下面的解决方案解决了这个问题。

在docker-compose中为其添加tty: trueyml文件。此外,为了使前端-后端交互在应用程序中按预期工作,更改客户端包中的代理命令。

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

和在docker-compose中更改链接命令。

- "backend:be"

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

相关内容

最新更新