module.js:550错误在Docker中找不到模块'猫鼬'

时间:2018-10-23 00:41:07

标签: node.js docker mongoose dockerfile package.json

我的package.json中有mongoose,当我运行npm install并在没有docker的情况下在本地运行应用程序(即npm start)时,它运行良好。

但是我正面临docker问题

我正在使用以下命令在docker上运行此应用程序 Docker build -t tony/dockertestproject . --no-cache

Successfully built

但是当我运行Docker run -p 3000:80 tony/dockertestproject

我遇到以下错误

> myapp@0.1.0 start /usr/src/app
> ./server.js

module.js:550
    throw err;
    ^

Error: Cannot find module 'mongoose'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/src/app/app.js:7:18)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! express-react-starter@0.1.0 start: `./server.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the express-react-starter@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-10-23T00_25_17_225Z-debug.log

package.json

{
  "name": "myapp",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "ajv": "^6.5.3",
    "async": "^2.6.1",
    "availity-reactstrap-validation": "^2.0.6",
    "axios": "^0.18.0",
    "body-parser": "^1.18.3",
    "bootstrap": "^4.1.3",
    "classnames": "^2.2.6",
    "cookie-parser": "^1.4.3",
    "crypto-js": "^3.1.9-1",
    "debug": "^4.1.0",
    "express": "^4.16.3",
    "form-data": "^2.3.2",
    "fs": "0.0.1-security",
    "jade": "^1.11.0",
    "jquery": "^3.3.1",
    "moment": "^2.22.2",
    "mongodb": "^3.1.8",
    "mongoose": "^5.3.5",
    "morgan": "^1.9.1",
    "prop-types": "^15.6.2",
    "querystring": "^0.2.0",
    "react": "^16.4.1",
    "react-bootstrap-table-next": "^1.1.3",
    "react-bootstrap-table2-filter": "^1.0.0",
    "react-bootstrap-table2-paginator": "^1.0.2",
    "react-dom": "^16.4.1",
    "react-dropzone": "^5.0.1",
    "react-redux": "^5.0.7",
    "react-toastify": "^4.3.0",
    "react-transition-group": "^2.3.1",
    "react-widgets": "^4.4.4",
    "react-widgets-moment": "^4.0.20",
    "reactstrap": "^6.1.0",
    "redux": "^4.0.0",
    "redux-form": "^7.4.2",
    "redux-thunk": "^2.3.0",
    "request": "^2.88.0",
    "uuid": "^3.3.0"
  },
  "devDependencies": {
    "concurrently": "^4.0.1",
    "eslint-config-airbnb-base": "^13.1.0",
    "eslint-plugin-import": "^2.14.0",
    "nodemon": "^1.18.4",
    "react-scripts": "^2.0.5"
  },
  "scripts": {
    "start": "concurrently \"react-scripts start\" \"nodemon server/server.js\"",
    "build": "react-scripts build && mv build server",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "proxy": "http://localhost:5000",
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

Dockerfile

FROM mhart/alpine-node:8
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# nvm environment variables
ENV NODE_VERSION 8.11.1
# Install app dependencies
COPY server/package.json /usr/src/app/
RUN npm install

# Bundle app source
COPY server/ /usr/src/app/
ENV PORT 80
# confirm installation
RUN node -v
RUN npm -v
CMD [ "npm", "start" ]

0 个答案:

没有答案