14
votes

I have a script running inside a docker-container which listens for changes in a directory via inotifywait. The directory is mounted to the host-system via docker -v.

For some reason, inotifywait doesn't get triggered when files inside this directory is changed.

This is the problematic script-line

inotifywait -e create -e modify -e delete -e move  /etc/nginx/sites-enabled

The container is started like this (via fig)

web:
  build: .
  ports:
   - "80:80"
  volumes:
   - ./conf:/etc/nginx/sites-enabled

When I start the setup via fig up, the script is executed, but changes in the mounted volume don't trigger the inotify-barrier.

2
I checked with a basic container, installed inotify-tools, started inotify, created a directory and a file, and was notified. So it seems related to volumes with docker -v - user2915097
docker != virtualization, maybe this is an edgecase where docker can't keep the isolation up. - Johannes Reuter
I'm seeing the same behavior using docker compose's (fig) volumes which are created with docker -v. - Leigh McCulloch
Five years later and this still doesn't work on docker edge with WSL2, linux container and mounted volume... Can't do react development with hot module replacement. - UmaN

2 Answers

0
votes

I had similar problem - missing inotify notifications inside of the docker container and its turned out that problem was in mounting alias folder as a volume, after replacing host folder to actual directory everything started to work.

In my case it was /tmp on OS X, therefore after replacing it to /private/tmp:/tmp the container started to receive inotify events.

0
votes

You have to add -mq to your script like this:

inotifywait -mq -e create -e modify -e delete -e move  /etc/nginx/sites-enabled

I have tested this solution and it works. The "m" is for "monitor" and "q" is for quiet.