0

I am working on a MERN Stack Project and I am trying to use Docker for both Development and Production version of the Project. I have created docker-compose for both modes (Dev , Prod) which has 3 services (Frontend, Backend, Database) Now Everything is Connecting correctly and working just fine but For publishing changes in Development mode I am using volumes in it and Now that I am a Windows user, The node_modules in my Project folder and the node_module in Container ( Which are Linux builds for same packages ) are generating Error. I am providing my Docker-Compose File as well.

Error

enter image description here

docker-compose.yml

services:
  devengers:
    container_name: devengers-root
    build: 
      context: .
      dockerfile: Dockerfile.development
    image: devengers

  backend:
    container_name: devengers-backend
    image: devengers    
    ports:
      - 3000:3000
    environment:
      - MONGODB_URL=mongodb://database:27017
    networks:
      - local_net
    depends_on:
      - devengers
      - database
    command: npm run start:dev
    volumes:
      - ".:/Devengers"
  
  frontend:
    container_name: devengers-frontend
    image: devengers
    ports:
      - 8080:8080
    environment:
      - API=http://backend:3000
    networks:
      - local_net
    depends_on:
      - backend
      - database
    command: npm run dev
    volumes:
      - ".:/Devengers"

  database:
    container_name: devengers-database
    image: mongo:4.0-xenial
    ports:
      - 27017:27017
    networks:
      - local_net
    volumes:
      - mongodb_data:/data/db

networks:
  local_net:

volumes:
  mongodb_data:

D_Gamer
  • 168
  • 12
  • remove node_modules, then `npm i` from within the container then it will work, you cant mix and match binarys between os's which is why node_modules is generally installed on the system its used on and ignored from git, builds etc – Lawrence Cherone Feb 24 '22 at 17:16
  • 1
    Does this answer your question? [Add a volume to Docker, but exclude a sub-folder](https://stackoverflow.com/questions/29181032/add-a-volume-to-docker-but-exclude-a-sub-folder) – BENARD Patrick Feb 24 '22 at 19:04
  • @LawrenceCherone I think if I'll remove node_modules from host directory then It'll give an error coz at Build time the Dockerfile runs `npm install` and it will generate `node_modules` but when then when I'll start that container it'll try to sync with my host directory and will remove the node_modules automatically. So then while starting the container I'll get `Dependencies not found` Error. – D_Gamer Feb 25 '22 at 05:03
  • @BENARDPatrick I raised this question after visiting the question you've referenced to. and No, that question's Solution didn't work for me. In there people are saying that if I dont want to sync node_modules then I'll simply have to provide just the Container `node_modules` directory path but As I read in [Docs](https://docs.docker.com/compose/compose-file/compose-file-v3/#volumes) It is just creating a random Volume Which won't be changing by changing my Host Directory so ultimately It won't sync node_modules. But that also didn't work. – D_Gamer Feb 25 '22 at 05:16

0 Answers0