title: How to sync node_modules directory from Docker container to Host machine?
body: <p>I use Ubuntu 22.04 as a host machine and Docker 20.10.17 for the container environment.</p>
  <p>Problem is that when I install the node packages inside the container, then I do not see these packages in the host machine in the node_modules folder, it's empty, so the IDE (Visual Studio Code) just gives errors in every TypeScript file cause of the missing node packages.</p>
  <p>However, in the container, I can see, the node pcakges are installed and there under the node_modules folder, so the application is up and live. So it works there, just locally, on my host machine is not available.</p>
  <p>I added the <code>node_modules</code> as a volume in the <code>docker-compose.yml</code>, but that trick does not work as I have seen this in other posts.</p>
  <pre><code>version: '3.8'
  
  services:
    web:
      container_name: web
      build:
        context: .
        dockerfile: Dockerfile
      volumes:
        - '.:/app'
        - '/app/node_modules'
      ports:
        - &quot;3000:3000&quot;
      environment:
        - NODE_ENV=development
        - CHOKIDAR_USEPOLLING=true
      stdin_open: true
  </code></pre>
  <p>Here is the Dockerfile:</p>
  <pre><code>FROM node:lts-alpine
  
  WORKDIR /app
  
  COPY package*.json ./
  
  # Fix Permissions for Packages
  # RUN npm config set unsafe-perm true
  
  RUN npm install -g npm
  RUN npm install
  
  COPY . .
  
  # Fix Cache Permissions for node_modules
  RUN chown -R node /app
  
  USER node
  
  EXPOSE 3000
  
  CMD [&quot;npm&quot;, &quot;run&quot;, &quot;dev&quot;]
  </code></pre>
  <p>The project structure looks like this on the host machine:</p>
  <pre><code>/
  - node_modules/
  - public/
  - src/
  - Dockerfile
  - docker-compose.yml
  </code></pre>