【问题标题】:issue with deploying create-react-app using docker使用 docker 部署 create-react-app 的问题
【发布时间】:2020-01-31 16:27:29
【问题描述】:

我正在尝试在卷的帮助下使用 docker compose 部署 create-react-app 项目。我在 Windows 10 机器上使用 Docker for Windows。我已经从项目中删除了 node_modules 文件夹,以便我可以利用 docker 文件中的 RUN npm install 。但我收到以下错误日志:

$ docker-compose up --build                                                                                             Building web
Step 1/7 : FROM node:alpine
 ---> ef7d474eab14
Step 2/7 : ENV NPM_CONFIG_LOGLEVEL warn
 ---> Using cache
 ---> 12e0998d080a
Step 3/7 : WORKDIR '/app'
 ---> Using cache
 ---> 696072685749
Step 4/7 : COPY package.json .
 ---> Using cache
 ---> 2de967d1753e
Step 5/7 : RUN npm install
 ---> Using cache
 ---> 7fff07ced071
Step 6/7 : COPY . .
 ---> Using cache
 ---> b0722839dcb8
Step 7/7 : CMD ["npm", "run", "start"]
 ---> Using cache
 ---> f5a645333123
Successfully built f5a645333123
Successfully tagged frontend_web:latest
Starting frontend_web_1 ... done                                                                                        Attaching to frontend_web_1
web_1  |
web_1  | > frontend@0.1.0 start /app
web_1  | > react-scripts start
web_1  |
web_1  | sh: react-scripts: not found
web_1  | npm ERR! code ELIFECYCLE
web_1  | npm ERR! syscall spawn
web_1  | npm ERR! file sh
web_1  | npm ERR! errno ENOENT
web_1  | npm ERR! frontend@0.1.0 start: `react-scripts start`
web_1  | npm ERR! spawn ENOENT
web_1  | npm ERR!
web_1  | npm ERR! Failed at the frontend@0.1.0 start script.
web_1  | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
web_1  | npm WARN Local package.json exists, but node_modules missing, did you mean to install?
web_1  |
web_1  | npm ERR! A complete log of this run can be found in:
web_1  | npm ERR!     /root/.npm/_logs/2019-10-02T11_14_03_294Z-debug.log
frontend_web_1 exited with code 1

我的 dockerfile.dev 如下:

FROM node:alpine

ENV NPM_CONFIG_LOGLEVEL warn

WORKDIR '/app'

COPY package.json .
RUN npm install 

COPY . . 

CMD ["npm", "run", "start"]

而Docker-compose.yml如下:

version : '3'
services : 
  web:  
    build: 
      context: .
      dockerfile: Dockerfile.dev
    ports: 
      - "3000:3000"
    volumes: 
      - .:/app 
      - /app/nodes_modules

请告诉我哪个步骤不正确?

【问题讨论】:

  • 你能解决这个问题吗?

标签: reactjs docker-compose docker-volume


【解决方案1】:

在 docker-compose.yml 中删除最后一行后尝试

- /app/nodes_modules

我认为问题是因为父级的两个卷首先也将 node_module 作为子目录,而第二个卷是由 docker 本身在 node_modules 文件夹的某个位置创建和管理的。所以似乎 node_module 文件夹的卷之间发生冲突

【讨论】:

    【解决方案2】:

    我认为您的 docker-compose 文件中有错字。 - /app/node_modules 不是 - /app/nodes_modules

    【讨论】:

      猜你喜欢
      • 2017-03-17
      • 1970-01-01
      • 2019-07-11
      • 2020-12-31
      • 1970-01-01
      • 1970-01-01
      • 2017-09-21
      • 2023-03-02
      • 2020-10-21
      相关资源
      最近更新 更多