使用 App Insights 工具构建和部署 NextJS 容器应用程序不起作用

问题描述 投票:0回答:1

我正在尝试为我的 nextjs 13.4.19 应用程序实现检测(使用页面目录)。在我的本地环境中使用

npm run dev
运行应用程序时,一切正常。然而,当尝试将应用程序构建到 Docker 映像并部署到生产环境时,似乎出现了问题,应用程序甚至无法自行启动。我无法调试原因。

我正在使用此处描述的仪器挂钩:https://nextjs.org/docs/pages/building-your-application/optimizing/instrumentation

我的

next.config.js
包含用于构建过程的
output: "standalone"
。我正在使用 nextjs 示例中的 docker 文件。一个非常简单的应用程序的完整代码可以在这里找到:

https://github.com/kubop/nextjs-appinsights-issue/tree/master

也许,我对 dockerfile 的定义是错误的?当尝试将 docker 映像部署到 Azure 容器应用程序时,日志包含如下内容:

startup probe failed: connection refused

当我尝试在本地运行容器时,使用

docker run -p 3000 myapp
我收到
- ready started server on 127.0.0.1:3000, url: http://127.0.0.1:3000
但是当尝试访问 URL 时,我得到:

localhost
didn’t send any data. ERR_EMPTY_RESPONSE

docker next.js dockerfile azure-application-insights instrumentation
1个回答
0
投票

我刚刚发现问题了。我不知道为什么,但由于某种原因,我的 dockerfile 中有

ENV HOSTNAME localhost
。将其更改为
ENV HOSTNAME "0.0.0.0"
解决了我的问题。

© www.soinside.com 2019 - 2024. All rights reserved.