Inotify not working on NFS type volumes

Inotify does not work when watching a bind mounted folder from a NFS source. Instead, if that NFS share is mounted on host and then that mount point used as volume source, it works as expected.

Host info:
Ubuntu 20.04.5 LTS

Docker version output:

Client: Docker Engine - Community
Cloud integration: 1.0.17
Version: 20.10.14
API version: 1.41
Go version: go1.16.15
Git commit: a224086
Built: Thu Mar 24 01:48:02 2022
OS/Arch: linux/amd64
Context: default
Experimental: true

Server: Docker Engine - Community
Engine:
Version: 20.10.14
API version: 1.41 (minimum version 1.12)
Go version: go1.16.15
Git commit: 87a90dc
Built: Thu Mar 24 01:45:53 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.13
GitCommit: 9cc61520f4cd876b86e77edfeb88fbcd536d1f9d
runc:
Version: 1.0.3
GitCommit: v1.0.3-0-gf46b6ba
docker-init:
Version: 0.19.0
GitCommit: de40ad0

NFS volume config on compose:

volumes:
  datalake:
    driver_opts:
      type: "nfs"
      o: "addr=x.x.x.x,nfsvers=4"
      device: ":/path/to/share"

I am surprised that Inotify works when the share is mounted on the host and used as a volume bind, but not when the nfs share is declared as named volume. It should pretty much have the same behavior, as under the hood docker doesn’t do anything different than you did: it mounts the remote share into /var/lib/docker/volumes/datalaka/_data when the container starts and binds the mountpont into the container path.

As to my knowledge Inotify watches are registed in the hosts’s kernel and only trigger on events known to the kernel (which still should be the case for a containerized process). If another host writes into the NFS share, the inotify event is not propagated to your docker host or a container.