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,271
  • 17
  • 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

2 Answers2

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
  • 181
  • 2
  • 13
-1

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.

Andriy Ivaneyko
  • 18,421
  • 4
  • 52
  • 73