简体   繁体   English

docker ubuntu 中的 nodejs 找不到模块 /usr/src/app/index.js

[英]nodejs in docker ubuntu cannot find module /usr/src/app/index.js

I'm trying to deploy an application I wrote to my unraid server so I had to docker-ize it.我正在尝试将我写的应用程序部署到我的 unraid 服务器上,所以我不得不对其进行 docker 化。 It's written with nodejs and depends on imagemagick and ghostscript so I had to include a build step to install those dependencies.它是用 nodejs 编写的,并且依赖于 imagemagick 和 ghostscript,所以我必须包含一个构建步骤来安装这些依赖项。 I'm seeing an error when running this image though我在运行此图像时看到错误

Here's my dockerfile这是我的 dockerfile

FROM node
RUN mkdir -p /usr/src/app
RUN chmod -R 777 /usr/src/app
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN npm i --only=production
FROM ubuntu
RUN apt-get update
RUN apt-get install -y imagemagick ghostscript nodejs
ENTRYPOINT node /usr/src/app/index.js

Console output控制台 output

internal/modules/cjs/loader.js:638
throw err;
^

Error: Cannot find module '/usr/src/app/index.js'

at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

Originally, my entrypoint was configured like ENTRYPOINT node./index.js but I thought that I was in the wrong directory or something but switching to an absolute path didn't work either so here I am.最初,我的入口点配置为ENTRYPOINT node./index.js但我认为我在错误的目录中,但切换到绝对路径也不起作用所以我在这里。

By using a second from instruction, you are instrucing a second stage.通过使用第二个指令,您正在指导第二个阶段。 Nothing from the first stage is availble to the second stage by default.默认情况下,第一阶段的任何内容都无法用于第二阶段。 If you need some artifacts you need to copy them explicitly.如果您需要一些工件,则需要显式复制它们。

FROM node as build
RUN mkdir -p /usr/src/app
RUN chmod -R 777 /usr/src/app
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN npm i --only=production

# this is a new stage
FROM ubuntu
RUN apt-get update
RUN apt-get install -y imagemagick ghostscript nodejs
# you need to copy the things you need 
COPY --from=builder /usr/src/app /usr/src/app
ENTRYPOINT node /usr/src/app/index.js

That said, it seems pointless for a node app to do that.也就是说,节点应用程序这样做似乎毫无意义。 I would suggest using a single stage.我建议使用单个阶段。 The node runtime is required to run your app.运行您的应用程序需要节点运行时。 Multi staging would make sense if you were to use node to build statics with something like webpack and then copy the produced statics into a second stage that doesn't need the node runtime.如果您要使用节点来构建具有 webpack 之类的静态数据,然后将生成的静态数据复制到不需要节点运行时的第二阶段,那么多阶段将是有意义的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:找不到模块“C:\Users\rodri\nodejs_paypal\src\index.js” - Error: Cannot find module 'C:\Users\rodri\nodejs_paypal\src\index.js' 在 docker 容器上运行 nodejs 应用程序会给出“错误:找不到模块'/usr/src/app/nodemon'” - Running a nodejs app on a docker container gives “ Error: Cannot find module '/usr/src/app/nodemon' ” 错误:找不到模块 '/var/app/current/NodeJS/index.js' + 502 Bad Gateway 错误 - Error: Cannot find module '/var/app/current/NodeJS/index.js' + 502 Bad Gateway error heroku 错误:找不到模块“/app/index.js” - heroku Error: Cannot find module '/app/index.js' 电子找不到模块/resources/app/index.js - Electron Cannot find module /resources/app/index.js Heroku 部署错误:找不到模块“/app/index.js” - Heroku Deploy Error: Cannot find module '/app/index.js' 找不到模块“ ./src/index.js”。 网站可以正常运行,但是为什么我必须重新部署才能解决此问题? - Cannot find module './src/index.js'. Website works but why do I have to redploy to fix this? 错误 in./src/app.js 模块构建失败(来自./node_modules/babel-loader/lib/index.js):错误:找不到模块'@babel/preset-present-env' - ERROR in ./src/app.js Module build failed (from ./node_modules/babel-loader/lib/index.js): Error: Cannot find module '@babel/preset-present-env' 错误:使用 docker-compose 时找不到模块“/usr/src/app/nodemon” - Error: Cannot find module '/usr/src/app/nodemon' while using docker-compose Docker:错误:找不到模块/app/src/myapp.js - Docker: Error: Cannot find module /app/src/myapp.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM