简体   繁体   中英

Docker-compose volumes not syncing with local files, works when I remove the volume for the local file

yesterday I updated Docker to version Docker version 19.03.5, build 633a0ea on Windows 10 Pro. All the projects were running correctly and no additional configuration has been made.

.dockerignore

node_modules
npm-debug.log
.gitignore
.env

docker-compose.yml

version: '3.7'
services:
  backend:
    build:
      context: .
    volumes:
      - .:/usr/src/app
      - node_modules:/usr/src/app/node_modules
      - .git:/usr/src/app/.git
    ports:
      - '5000:5000'
      - '9229:9229'
    links:
      - mongo
    environment:
      - CHOKIDAR_USEPOLLING=true
  mongo:
    image: mongo
    ports:
      - '27017:27017'

volumes:
  node_modules:

Dockerfile

FROM node:10
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 5000
CMD npm run server

After I execute docker-compose up --build I get the following error:

backend_1  | > nodemon server.js
backend_1  |
backend_1  | sh: 1: nodemon: not found
backend_1  | npm ERR! code ELIFECYCLE
backend_1  | npm ERR! syscall spawn
backend_1  | npm ERR! file sh
backend_1  | npm ERR! errno ENOENT
backend_1  | npm ERR! project-api@1.0.1 server: `nodemon server.js`
backend_1  | npm ERR! spawn ENOENT
backend_1  | npm ERR!
backend_1  | npm ERR! Failed at the project-api@1.0.1 server script.
backend_1  | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
backend_1  |
backend_1  | npm ERR! A complete log of this run can be found in:
backend_1  | npm ERR!     /root/.npm/_logs/2020-01-23T04_11_11_071Z-debug.log

My folder structure is the following:

root
  | client
    | .dockerignore
    | docker-compose.yml
    | Dockerfile
    | package-lock.json
    | package.json
  ...
  | .dockerignore
  | docker-compose.yml
  | Dockerfile
  | package-lock.json
  | package.json
  | server.js

As you can see, I also have another project inside and it's running how it should.

Update package.json with local nodemon path which is comes from the node_modules folder.

like:

./node_modules/nodemon/bin/nodemon.js server.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM