我正在尝试借助docker compose在卷的帮助下部署create-react-app项目。我在Windows 10计算机上使用Windows的Docker。我已从项目中删除了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
请让我知道哪个步骤不正确?
答案 0 :(得分:0)
在删除docker-compose.yml中的最后一行后尝试
- /app/nodes_modules
我认为问题是因为两个卷首先用于父级,这两个卷也将node_module用作子目录,而第二个卷则由docker本身在node_modules文件夹的某个地方创建和管理。因此,似乎node_module文件夹的卷之间存在冲突
答案 1 :(得分:0)
我认为您的docker-compose文件中有拼写错误。 -/ app / node_modules不是-/ app / node s _modules