我正在 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
在几条读取等待对容器 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.yml 文件中添加 tty: true 。另外,为了使前后端交互在应用程序中按预期工作,请将客户端的 package.json 中的代理命令更改为以下内容:
“代理”:“http://backend:5000”
并将 docker-compose.yml 中的 links 命令更改为:
- "backend:be"
在此分享答案,以帮助将来可能遇到相同问题的其他人。
关于node.js - Azure 部署失败 - 容器未响应端口 : 8080, 上的 HTTP ping,站点启动失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66196997/