gpt4 book ai didi

node.js - Docker 运行 NodeJS 应用程序抛出错误找不到模块

转载 作者:太空宇宙 更新时间:2023-11-03 23:50:57 24 4
gpt4 key购买 nike

我是 docker 构建功能的新手。我正在尝试为我的 node.js 应用程序创建 docker 镜像,但是我遇到了问题。
1)它显示图像已创建,但是当我尝试 docker 运行时,它给出错误,如

"module.js:550
throw err;
^

Error: Cannot find module '

我认为我的 docker 文件存在一些问题。我已经创建了,但我不明白问题到底是什么我的 Dockerfile

FROM ubuntu:16.04
RUN apt-get update -y
RUN apt-get install g++ -y
RUN apt install curl -y
RUN curl --silent --location https://deb.nodesource.com/setup_8.x — Node.js 8 LTS "Carbon" | bash -
RUN apt-get install --yes nodejs
RUN apt-get install --yes build-essential
# check the path
WORKDIR /usr/src/app

COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 9012
CMD ["node", "app.js"]

另请参阅我的 package.json 了解更多信息。模块数。

{
"name": "service",
"version": "0.0.0",
"private": true,
"scripts": {
"serve": "nodemon app.js"
},
"description": "test",
"author": {
"name": "caitayl"
},
"dependencies": {
"body-parser": "~1.8.1",
"config": "^1.28.1",
"cookie-parser": "~1.3.3",
"cors": "^2.8.5",
"debug": "~2.0.0",
"ejs": "^2.7.1",
"express": "^4.17.1",
"fabric-ca-client": "~1.4.0",
"fabric-network": "~1.4.0",
"firebase": "^6.4.0",
"firebase-admin": "^8.4.0",
"http-errors": "~1.6.3",
"json-server": "^0.15.0",
"lodash": "^4.17.15",
"method-override": "^2.3.10",
"mongodb": "^3.4.1",
"morgan": "~1.9.1",
"multer": "^1.4.1",
"nexmo": "^2.4.1",
"node-gyp": "^5.0.3",
"node-pre-gyp": "^0.13.0",
"node-rest-client": "^3.1.0",
"os": "^0.1.1",
"paypal-rest-sdk": "^1.8.1",
"qs": "^6.8.0",
"sendotp": "^1.2.9",
"socket.io": "^2.2.0",
"winston": "^2.4.2",
"winston-mongodb": "^2.0.10"
},
"devDependencies": {
"nodemon": "^1.19.1"
}
}

最佳答案

既然已经有了official ones,为什么还要从ubuntu制作nodejs镜像呢? .

我发现问题 - 您使用不必要的步骤对 Dockerfile 进行了过度设计。

修复您的 Dockerfile 并重试:

FROM node:8-alpine3.9

RUN apk update
RUN apk add --no-cache g++ make python python-dev
RUN rm -rf /var/cache/apk/*

WORKDIR /app

COPY package*.json ./

RUN npm i

COPY . .

EXPOSE 9012
CMD node app.js

从上次合作中,我发现代码中存在拼写错误,您需要来自不存在的文件夹的文件。

"module.js:550 throw err; ^ Error: Cannot find module '../dFarmUserService/controllers/ClientRegisterController' 

所以把它固定在一起:)

关于node.js - Docker 运行 NodeJS 应用程序抛出错误找不到模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59504828/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com