【发布时间】: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