NextJS应用程序在Docker中崩溃,没有日志

huangapple go评论64阅读模式
英文:

NextJS App Crashing within Docker With No Logs

问题

我正在尝试在 Docker 容器中运行一个 NextJS 应用程序。我正在使用 Prisma 连接到我的数据库,并使用 NextAuth 进行 OAuth 认证。

如果我在本地运行应用程序,我能够成功登录(即,我可以按预期完成整个流程)。

然而,如果我在 Docker 容器中运行它,一旦我访问pages/api/auth[...nextAuth].ts 路由,就会出现错误。

我似乎只能获取到以下日志:

docker-crud-next-1      | wait  - compiling /api/auth/[...nextauth] (client and server)...
docker-crud-next-1      | event - compiled client and server successfully in 5.9s (610 modules)
docker-crud-next-1 退出,代码为0

我尝试按照调试器文档的步骤进行,但无法使其在 Docker 容器中正常工作。

我还尝试从容器内部手动运行应用程序,但情况相同 - 应用程序崩溃,没有日志可供查看。

也就是说,我创建容器,然后打开交互式 shell 并手动运行启动命令。从日志的角度来看没有改进。

认为 可能是 Prisma 客户端(这里)... 但我不知道是什么导致应用程序崩溃。

所以,问题如下:

  1. 有没有更好的方法获取日志,以便我能够找出 为什么 应用程序崩溃?
  2. 为什么它在本地可能正常工作,但在容器中不行?

我使用的是 Mac 13.1,带有 Intel 处理器(不是 M1/2 芯片)。
我了解到我正在使用 Debian 基础的 Docker 容器(尽管,这可能是第3个问题 -- 如何查询我正在使用的镜像,因为它是基于 Microsoft 的 Typescript Node 镜像)。

英文:

I'm trying to run a NextJS app in a docker container. I'm using Prisma to connect to my database and NextAuth for OAuth.

If I run the app locally, I am able to successfully login (i.e., I can run through the whole flow as expected).

However, if I run it in the docker container, I'm getting errors as soon as I hit my pages/api/auth[...nextAuth].ts route.

The only logs I seem to be able to get are:

docker-crud-next-1      | wait  - compiling /api/auth/[...nextauth] (client and server)...
docker-crud-next-1      | event - compiled client and server successfully in 5.9s (610 modules)
docker-crud-next-1 exited with code 0

I've tried following the debugger docs, but am not able to get it to work within the docker container?

I've also tried running the app manually from within the container, but same situation - the app just dies and there are no logs to look at.

I.e., I create the container, then open an interactive shell and manually run the start commands. No improvement from a logs perspective. ,

I think it might be the prisma client (here)... but I'm at a loss to figure out what is causing the app to crash.

So, questions:

  1. What's the better way to get logs so I can figure out why it's crashing?
  2. Any idea why it might work locally but not in the container?

I'm on Mac 13.1 on with an Intel (not M1/2 chip).
My understanding is that I'm using a Debian base for my docker container (though, that's probably question 3 -- how can I interrogate the image I'm using since it's based on Microsoft's Typescript Node image)

答案1

得分: 1

代码部分不翻译:

The issue appears to have been related to the base image I have been using.

I missed a disclaimer when porting a project from a different machine (an M1 mac) onto this one (an intel based Mac) that the image I was using reserves the -bullseye variant for M1 (source).

Moving to the base image without a variant worked:

FROM mcr.microsoft.com/vscode/devcontainers/typescript-node as base

or using a the even more basic node:18-alpine.

Interestingly, trying to tag the typescripte-node image with a variant of 18 did not seem to work:

ARG VARIANT="18"
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT} as base

Either way, I now have a working app and Next isn't crashing. I would still love someone to help me understand what dependency was crashing and even better how I could have detected it because my logs were still totally bare.

英文:

The issue appears to have been related to the base image I have been using.

I missed a disclaimer when porting a project from a different machine (an M1 mac) onto this one (an intel based Mac) that the image I was using reserves the -bullseye variant for M1 (source).

Moving to the base image without a variant worked:

FROM mcr.microsoft.com/vscode/devcontainers/typescript-node as base

or using a the even more basic node:18-alpine.

Interestingly, trying to tag the typescripte-node image with a variant of 18 did not seem to work:

ARG VARIANT="18"
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT} as base

Either way, I now have a working app and Next isn't crashing. I would still love someone to help me understand what dependency was crashing and even better how I could have detected it because my logs were still totally bare.

huangapple
  • 本文由 发表于 2023年2月16日 09:50:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/75467083.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定