我是docker build功能的新手。我正在尝试为我的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"]
另请参阅my 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"
}
}
答案 0 :(得分: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'
因此将其固定在一起:)