docker-compose 无法以 npm ERR 启动!enoent ENOENT: 没有那个文件或目录,打开'/usr/src/app/package.json' [英] docker-compose fails to start with npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/app/package.json'

查看:65
本文介绍了docker-compose 无法以 npm ERR 启动!enoent ENOENT: 没有那个文件或目录,打开'/usr/src/app/package.json'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 docker 文件构建了一个图像来运行 node 并复制到一个简单的 node express 应用程序中,该应用程序运行良好.图像构建我可以运行容器和 bash 并复制本地文件.当我在 docker-compose 文件中使用此图像以及 mongo 图像时,容器构建但节点容器无法运行,错误是缺少 package.json.

I built an image from a docker file to run node and copy in a simple node express app which works perfectly. The image builds I can run a container and bash in and the local files are copied. When I use this image in a docker-compose file along with a mongo image the containers build but the node container fails to run with an error is the package.json is missing.

返回的错误是

report-node exited with code 254
report-node | npm ERR! path /usr/src/app/package.json
report-node | npm ERR! code ENOENT
report-node | npm ERR! errno -2
report-node | npm ERR! syscall open
report-node | npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/app/package.json'
report-node | npm ERR! enoent This is related to npm not being able to find a file.
report-node | npm ERR! enoent
report-node |
report-node | npm ERR! A complete log of this run can be found in:
report-node | npm ERR!     /root/.npm/_logs/2019-02-26T10_55_05_562Z-debug.log
report-node exited with code 254

docker 文件

FROM node
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 4000
CMD [ "npm", "run", "dev"  ]

Docker-compose.yml 看起来像

Docker-compose.yml looks like

version: '3'
services:
  app:
    image: gosmith/node10:latest
    container_name: report-node
    restart: always
    volumes:
      - ./:/usr/src/app
    working_dir: /usr/src/app
    depends_on:
      - mongo
    environment:
      NODE_ENV: development
    ports:
      - 4000:4000
      - 8080:8080
    command: npm run dev && npm run serve
  mongo:
    container_name: mongo
    image: mongo
    expose:
      - 27017
    ports:
      - 27037:27017
    volumes:
      - ./data:/data/db

package.json 怎么不见了?感谢您的帮助!

How has the package.json gone missing? Thanks for your help!

推荐答案

当你的 docker-compose.yml

volumes:
  - ./:/usr/src/app

它隐藏了在 Dockerfile 中完成的所有事情,并将其替换为当前目录.如果您的当前目录没有 package.json 文件(也许您将与 Docker 相关的所有内容都移到了子目录中),则会导致您看到的错误.

it hides everything that gets done in the Dockerfile and replaces it with the current directory. If your current directory doesn't have the package.json file (maybe you moved everything Docker-related into a subdirectory) it will cause the error you see.

就我个人而言,我只想删除这两行,在本地开发我的应用程序(不使用 Docker,使用每个项目的 node_modules 目录进行隔离),并且仅在我真正准备好时才构建 Docker 映像部署它.

Personally I would just remove these two lines, develop my application locally (without Docker, using the per-project node_modules directory for isolation), and only build the Docker image when I'm actually ready to deploy it.

这篇关于docker-compose 无法以 npm ERR 启动!enoent ENOENT: 没有那个文件或目录,打开'/usr/src/app/package.json'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆