inotify does not work for bind mounts or root mount modifications
- Dominant language
- Go
- Stars
- 19.3k
- Forks
- 2k
- Avg merge
- 3d 5h
- Merged PRs (30d)
- 264
Description
### Description
Running a program which uses inotify to monitor for filesystem changes will not be notified for changes to files bind mounted into a container running in gVisor, nor will it be notified of changes to the root filesystem (i.e. via `docker cp` with `--file-access=shared`).
inotify works fine for files on the root filesystem itself. `stat` shows changes to the bind mounted or modified root filesystem files, but a simple program using inotify will not see those changes.
### Steps to reproduce
Example `Dockerfile`:
```Dockerfile
FROM debian:bullseye
RUN apt-get update
RUN apt-get install -y python3 python3-pip
RUN pip install watchdog
WORKDIR /root
COPY test.py test.py
```
`test.py`:
```test.py
#!/usr/bin/env python3
import sys
import time
import logging
from watchdog.observers import Observer
from watchdog.events import LoggingEventHandler
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
path = sys.argv[1] if len(sys.argv) > 1 else '.'
event_handler = LoggingEventHandler()
observer = Observer()
observer.schedule(event_handler, path, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
```
Create test container:
`docker run --runtime=runsc -it --rm -v /tmp:/tmp watchdog-test /bin/bash`
Run test program in container:
`./test.py /tmp`
Touch test file on host:
`touch /tmp/t`
No notify events will be shown by test program.
Compare to running without `--runtime=runsc`:
```
[mhoran@challenger] ~/t% docker run -it --rm -v /tmp:/tmp watchdog-test /bin/bash
root@f23a8908a26e:~# ./test.py /tmp
2022-10-14 21:26:35 - Modified file: /tmp/t
2022-10-14 21:26:35 - Modified directory: /tmp
```
The same happens for a file copied to the root filesystem when `--file-access=shared` is used.
### runsc version
```shell
runsc version release-20221010.0-9-g49874d2cff79
spec: 1.0.2-dev
```
### docker version (if using docker)
```shell
Client: Docker Engine - Community
Version: 20.10.19
API version: 1.41
Go version: go1.18.7
Git commit: d85ef84
Built: Thu Oct 13 16:46:45 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.19
API version: 1.41 (minimum version 1.12)
Go version: go1.18.7
Git commit: c964641
Built: Thu Oct 13 16:44:36 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.8
GitCommit: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
runc:
Version: 1.1.4
GitCommit: v1.1.4-0-g5fd4c4d
docker-init:
Version: 0.19.0
GitCommit: de40ad0
```
### uname
Linux challenger 5.10.0-18-amd64 #1 SMP Debian 5.10.140-1 (2022-09-02) x86_64 GNU/Linux
### kubectl (if using Kubernetes)
_No response_
### repo state (if built from source)
_No response_
### runsc debug logs (if available)
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.