Sveltekit docker 容器启动时出错
我正在尝试从我的 sveltekit 应用程序获取 docker 容器。 我在 svelte.config.js 中使用节点适配器
import adapter from '@sveltejs/adapter-node'
adapter: adapter(),
,我的 Dockerfile 如下所示。
FROM node:16-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . ./
RUN npm run build
EXPOSE 3000
CMD [ "node", "build" ]
启动容器时出现此错误:
node:internal/errors:464
2022-03-02T09:51:03.597044200Z ErrorCaptureStackTrace(err);
2022-03-02T09:51:03.597088700Z ^
2022-03-02T09:51:03.597100400Z
2022-03-02T09:51:03.597116300Z Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/app/build/server/index.js' imported from /app/build/index.js
2022-03-02T09:51:03.597144200Z at new NodeError (node:internal/errors:371:5)
2022-03-02T09:51:03.597193600Z at finalizeResolution (node:internal/modules/esm/resolve:418:11)
2022-03-02T09:51:03.597270100Z at moduleResolve (node:internal/modules/esm/resolve:981:10)
2022-03-02T09:51:03.597285100Z at defaultResolve (node:internal/modules/esm/resolve:1078:11)
2022-03-02T09:51:03.597298100Z at ESMLoader.resolve (node:internal/modules/esm/loader:530:30)
2022-03-02T09:51:03.597311100Z at ESMLoader.getModuleJob (node:internal/modules/esm/loader:251:18)
2022-03-02T09:51:03.597324900Z at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:79:40)
2022-03-02T09:51:03.597336000Z at link (node:internal/modules/esm/module_job:78:36) {
2022-03-02T09:51:03.597345300Z code: 'ERR_MODULE_NOT_FOUND'
2022-03-02T09:51:03.597359500Z }
I'm trying to get a docker container from my sveltekit app.
I'm using the node adapter in my svelte.config.js
import adapter from '@sveltejs/adapter-node'
adapter: adapter(),
and my Dockerfile looks like this.
FROM node:16-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . ./
RUN npm run build
EXPOSE 3000
CMD [ "node", "build" ]
I'm getting this error when starting up the container:
node:internal/errors:464
2022-03-02T09:51:03.597044200Z ErrorCaptureStackTrace(err);
2022-03-02T09:51:03.597088700Z ^
2022-03-02T09:51:03.597100400Z
2022-03-02T09:51:03.597116300Z Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/app/build/server/index.js' imported from /app/build/index.js
2022-03-02T09:51:03.597144200Z at new NodeError (node:internal/errors:371:5)
2022-03-02T09:51:03.597193600Z at finalizeResolution (node:internal/modules/esm/resolve:418:11)
2022-03-02T09:51:03.597270100Z at moduleResolve (node:internal/modules/esm/resolve:981:10)
2022-03-02T09:51:03.597285100Z at defaultResolve (node:internal/modules/esm/resolve:1078:11)
2022-03-02T09:51:03.597298100Z at ESMLoader.resolve (node:internal/modules/esm/loader:530:30)
2022-03-02T09:51:03.597311100Z at ESMLoader.getModuleJob (node:internal/modules/esm/loader:251:18)
2022-03-02T09:51:03.597324900Z at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:79:40)
2022-03-02T09:51:03.597336000Z at link (node:internal/modules/esm/module_job:78:36) {
2022-03-02T09:51:03.597345300Z code: 'ERR_MODULE_NOT_FOUND'
2022-03-02T09:51:03.597359500Z }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以构建一个临时 docker 映像,然后首先在该映像中构建您的项目。之后,您可以使用之前的构建映像创建最终的生产 docker 映像。所以,dockerfile 应该如下所示。
You can build a temporary docker image and build your project inside that image first. After, you can create your final production docker image using the prior build image. So, dockerfile should be like the below.