Mount binds not working

So I am new to this and wanted to practice. I created a simple node project:

Screenshot 2024-05-27 014915

I setup express and nodemon. When I run my project locally it works, if I change the code and reload it reflects.

Dockerfile:

FROM node:18.12.1-alpine

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY ./src ./src

EXPOSE 8080

CMD ["npm", "run", "dev"]

package.json:

 "scripts": {
    "start": "node src/index.js",
    "dev": "nodemon --watch \"./**\" --ext \"js\" --exec \"node src/index.js\""
  },

If I run docker run -v ./src:/src/app/ -p 8080:8080 davihlav/frontend:v1 while in frontend folder changing the code doesn’t update.

Likewise in docker-compose.yml:

version: '3'
services:
  frontend:
    image: davihlav/frontend:v1
    build: ./frontend
    ports:
      - "8080:8080"
    volumes:
      - ./frontend/src:/app/src

Running docker-compose up --build in the root folder code update doesn’t work. What am I doing wrong?

You run this in Windows with Docker Desktop or WSL?

The application or the content of the folder? If the application, it has nothing to do with the bind mount mentioned in the title.

I have Docker Desktop installed, Im running this in vscode terminal

Doesn’t matter right? If the content changes so should the application

It does matter. That’s why I ask. You can find many topics about it related to nodejs and monitoring content. Bind mount just shares the files with the container, but how the changes can be monitored and how the application can reload the source code, that’s another story.

The version of your Docker Desktop is also important, as there was a bug in a recent version that bind mounted folders were indeed not synchronized with the virtual machine of Docker Desktop.