Issue with Binding Local Folder to Docker Container on Windows 11

Hello Docker Community,

I’m currently facing an issue with Docker on my Windows 11 machine. I’m trying to bind my local folder to a Docker container, but it’s not working as expected. The same setup works fine on my Mac OS.
Here’s my setup:

I am trying to dockerize environment for a simple node js app.
My docker-compose.yaml

services:
  mymongodb:
    image: mongo:latest
    ports:
      - "27018:27017"
    volumes:
      - prateek-mongo:/data/db
  my_custom_app:
    build: ./
    ports:
      - "3001:3001"
    volumes:
      - ./:/usr/src/app

volumes:
  prateek-mongo:

.Docker file

FROM mhart/alpine-node

WORKDIR /usr/src/app

COPY . .

RUN npm install

EXPOSE 3001

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

index.js file

import express from "express";
import { Entry } from "./db.js";

const app=express();

const PORT=process.env.PORT||3001;

app.get('/',async (req,res)=>{
    try {
        const entry = new Entry({ text: 'This is an  second entry' });
        await entry.save();
        res.send('Entry added second time !');
      } catch (err) {
        res.status(500).send('Error occurred');
      }
});


app.listen(PORT,()=>{
    console.log(`Server Started at PORT ${PORT}`);
})

Folder Structure

    .gitignore
    db.js
    docker-compose.yml
    Dockerfile
    index.js
    package-lock.json
    package.json

The issue is that when I run the container, the local folder doesn’t seem to bind with the Docker container. I’ve tried several solutions but none seem to work. Any help would be greatly appreciated.
also when I remove this piece from my docker-compose file

    volumes:
      - ./:/usr/src/app

it work fine in windows,but I am not able to make my server start with changes ,I have to again compose up .

Thank you in advance!

And how did you confirm it?

For me, it seems you want to mount your built app inside the container to the Windows host. It wouldn’t work on macOS either. If it worked, you probably had the app on the host already. With this compose file, you just override the content in the container with your folder on the host which doesn’t have the result of npm install.

Here is a blogpost which was inspired by the frequent report of these kind of issues

Please, correct me if I misunderstood you.

Thank you for your response.

To clarify, my goal is to create a system where changes made to a file locally are reflected in the Docker container. To achieve this, I’ve bound the local directory to the code inside the container using the following line in my docker-compose file:

volumes:
  - ./:/usr/src/app

On my Mac, when I make a change locally, the server running in the Docker container restarts instantly. This behavior indicates that the local folder is successfully mounted to the Docker container. However, when I try the same setup on my Windows machine, it doesn’t work as expected.

Thanks.

So if the sourcecode is actually mapped to the container, it could be related to these issues:

Since macOS and Linux are both unix like, Windows could be different