我已经创建了Web应用-前端的react和backend nodejs。我正在尝试在docker compose中运行它。 后端Dockerfile
FROM node:12.10.0-alpine
WORKDIR /usr/app
COPY package*.json ./
RUN npm ci -qy
COPY . .
EXPOSE 8081
CMD ["npm", "start"]
我的Docker组成文件:
version: '2'
services:
server:
build:
context: ./server/
command: /usr/app/node_modules/.bin/nodemon index.js
volumes:
- ./server/:/usr/app
- /usr/app/node_modules
ports:
- "8081:8081"
# env_file: ./server/.env # TODO - uncomment this to auto-load your .env file!
environment:
- NODE_ENV=development
- CHOKIDAR_USEPOLLING=true
client:
build:
context: ./client/
command: npm start
volumes:
- ./client/:/usr/app
- /usr/app/node_modules
depends_on:
- server
ports:
- "3000:3000"
当我尝试运行它时,出现此错误,后端退出并显示代码1:
Attaching to node-react-docker-compose-master_server_1, node-react-docker-compose-master_client_1
server_1 | internal/modules/cjs/loader.js:775
server_1 | throw err;
server_1 | ^
server_1 |
server_1 | Error: Cannot find module '/usr/app/node_modules/.bin/nodemon'
server_1 | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:772:15)
server_1 | at Function.Module._load (internal/modules/cjs/loader.js:677:27)
server_1 | at Function.Module.runMain (internal/modules/cjs/loader.js:999:10)
server_1 | at internal/main/run_main_module.js:17:11 {
server_1 | code: 'MODULE_NOT_FOUND',<br/>
server_1 | requireStack: []
server_1 | }
client_1 |
client_1 | > hlad-client@0.1.0 start /usr/app
client_1 | > react-scripts start
client_1 |
node-react-docker-compose-master_server_1 exited with code 1
在node_modules / .bin / nodemon中的模块nodemon,但是存在。谢谢你的建议。