找不到模块'/ src / bin / www'-Docker和Mean Stack

时间:2020-02-06 16:26:04

标签: node.js angular docker express

创建第一个Docker容器时遇到问题。输入Cannot find module '/src/bin/www'时,我不断收到错误消息,说docker-compose up在package.json文件中,我尝试了"start": "node /bin/www""start": "node ./bin/www",但问题相同。同样是我第一次运行它,它花了大约一分钟,但是从那以后,当我运行它时,它在几秒钟内抛出了错误。不知道这是否相关。

> backend@1.0.0 start /src
node_1  | > node ./bin/www
node_1  |
node_1  | internal/modules/cjs/loader.js:983
node_1  |   throw err;
node_1  |   ^
node_1  |
node_1  | Error: Cannot find module '/src/bin/www'
node_1  |     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
node_1  |     at Function.Module._load (internal/modules/cjs/loader.js:862:27)
node_1  |     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
node_1  |     at internal/main/run_main_module.js:17:47 {
node_1  |   code: 'MODULE_NOT_FOUND',
node_1  |   requireStack: []
node_1  | }
node_1  | npm ERR! code ELIFECYCLE
node_1  | npm ERR! errno 1
node_1  | npm ERR! backend@1.0.0 start: `node ./bin/www`
node_1  | npm ERR! Exit status 1
node_1  | npm ERR!
node_1  | npm ERR! Failed at the backend@1.0.0 start script.
node_1  | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
node_1  |
node_1  | npm ERR! A complete log of this run can be found in:
node_1  | npm ERR!     /root/.npm/_logs/2020-02-06T16_09_20_442Z-debug.log
myapp-docker_node_1 exited with code 1
Gracefully stopping... (press Ctrl+C again to force)

package.json

{
  "name": "backend",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node /bin/www"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "aws-sdk": "^2.612.0",
    "bcrypt": "^3.0.8",
    "body-parser": "^1.19.0",
    "create-hash": "^1.2.0",
    "crypto": "^1.0.1",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "jsonwebtoken": "^8.5.1",
    "mongoose": "^5.8.11",
    "mongoose-unique-validator": "^2.0.3",
    "multer": "^1.4.2",
    "multer-s3": "^2.9.0"
  }
}

docker-compose.yml

version: '3'
services:
    web:
        build: ./frontend
        ports:
            - "80:80"
        links:
        - node
        volumes:
        - "/Users/Phil/Documents/mysite/mysite-docker/frontend/dist:/usr/share/nginx/html"
    node:
        build: ./backend
        ports:
        - "3000:3000"

前端docker文件

FROM nginx
MAINTAINER Phil


VOLUME /Users/Phil/Documents/mysite/mysite-docker/frontend/dist:usr/share/nginx/html

EXPOSE 80

后端docker文件


FROM node

MAINTAINER Phil

WORKDIR /src

COPY . /src

RUN npm install

RUN npm install -g nodemon

EXPOSE 3000

CMD ["npm", "start"]

enter image description here

0 个答案:

没有答案