Compose Watch Only Detecting New Files

Ubuntu 20.04.6 running in WSL2
Docker Compose version 2.26.1

Having an issue where creating new files will trigger my compose watch action, but editing and saving files in the same directory won’t.

Using my IDE (Intellij IDEA) or notepad to edit and save a file doesn’t trigger my watch action, but creating a new file or echoing a string into an existing file will. not too sure on how echo actually works behind the scenes, it would make sense if it’s like vim and creates a hidden swap file, which would obviously be creating a new file, and trigger the action.

Here’s what my compose.yaml looks like:

services:
  db:
    image: postgres:latest
    env_file:
      - .env
    ports:
      - 5432:5432
    volumes:
      - db:/var/lib/postgresql/data
    networks:
      - backend
  backend:
    build: .
    develop:
      watch:
        - action: rebuild
          path: ./project-planner-api/
          target: /project-planner-api/
    image: bellsoft/liberica-runtime-container:jdk-17-glibc
    env_file:
      - ./project-planner-api/.env
    ports:
      - 3000:3000
    networks:
      - backend
    depends_on:
      - db
    command:
      ./gradlew bootRun

volumes:
  db:
    driver: local

networks:
  backend: {}

And dockerfile:

FROM bellsoft/liberica-runtime-container:jdk-17-glibc
USER backend
WORKDIR /project-planner-api
COPY --chown=backend:backend ./project-planner-api .
EXPOSE 3000

I’m trying to set up a dev environment for my team to use for a new project. I have tried spring devtools for hot reloading, but that requires your IDE to rebuild every time before it picks up changes, which I feel kind of defeats the point of creating a docker environment. The reason I’m using docker is so that we don’t need to worry about who’s running what, and getting people to install and setup postgres, and specific jdks. Currently if I add a new file to the /project-planner-api/ directory, it will rebuild, and is quick enough for me to be satisfied. Just not working with editing files.

As alluded to here and here , it turns out this is a WSL issue. If you’re launching docker from wsl, but working in a windows directory, file edits aren’t propagated to the container properly, and the watch will not trigger. I solved the issue by moving my project directory inside of wsl, and running my containers from there.