Install all needed node modules inside Docker container, not just copying them

  docker, docker-compose, node-modules, node.js, npm

The problem is the following. We have a project with several services running with docker compose.
When one of us adds a new module with npm install <module name> --save, the package*.json files are going to be updated and the module is going to be installed in the node_module folder.
Here, running docker-compose up --build everything works fine.
Nevertheless, when someone else pulls the updated versions of the package*.json files and tries to run docker-compose up --build Docker outputs the error that the module is not found.
It seems like the local node_module folder is copied directly into the Docker container.

The question is how can we make it possible that all needed node modules which are in the package*.json files are going to be installed inside the container not just copied?

Here is one DOCKERFILE:

FROM node:14

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 3000

CMD npm run devStart

as well as the docker-compose.yaml file:

version: "3"
services:
  list-service:
    build:
      context: ./list-service
      dockerfile: Dockerfile
    ports:
      - "4041"
    volumes:
      - ./list_service:/usr/src/app
      #- /usr/src/app/node_modules
  
  user-service:
    build:
      context: ./user_service
      dockerfile: Dockerfile
    ports:
      - "4040"
    volumes:
      - ./user_service:/usr/src/app
     # - /usr/src/app/node_modules

  api-gateway:
    build:
      context: ./api_gateway
      dockerfile: Dockerfile
    ports:
      - "5000:5000"
    volumes:
      - ./api_gateway:/usr/src/app
     # - /usr/src/app/node_modules

  date_list-service:
    build:
      context: ./date_list_service
      dockerfile: Dockerfile
    ports:
     - "4042"
    volumes:
      - ./date_list_service:/usr/src/app
    #  - /usr/src/app/node_modules

  mongo:
    container_name: mongo
    image: mongo
    command: mongod --port 27018
    volumes:
      - data:/data/db
  
volumes:
  data:

Source: Docker Questions

LEAVE A COMMENT