15

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.

Johannes Reuter
  • 3,501
  • 19
  • 20
  • 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 Jan 13 '15 at 10:21
  • docker != virtualization, maybe this is an edgecase where docker can't keep the isolation up. – Johannes Reuter Jan 13 '15 at 11:22
  • I'm seeing the same behavior using docker compose's (fig) volumes which are created with `docker -v`. – Leigh McCulloch Apr 18 '15 at 15:12
  • 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 May 24 '20 at 09:05

1 Answers1

1

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.

Goose
  • 351
  • 4
  • 15
  • It depends on what you want, if you want inotifywait to stop watching after a change occurred you don't want the -m option. So for example if you have a script like: `inotifywait && echo "Change detected"` you don't want the -m option because it will wait forever and never get to the echo statement. – Floris Groenendijk Feb 08 '23 at 11:19