swoole / docker-swoole

🏄 Official Docker Image of Swoole
https://hub.docker.com/r/phpswoole/swoole
Apache License 2.0
526 stars 112 forks source link

Failed to watch /var/www; upper limit on inotify watches reached! #14

Closed nezamy closed 4 years ago

nezamy commented 4 years ago

I'm using the auto-reload example and I get this after a few changes in files

Failed to watch /var/www; upper limit on inotify watches reached!
Please increase the amount of inotify watches allowed per user via `/proc/sys/fs/inotify/max_user_watches'.
swoole: ERROR (not running)
deminy commented 4 years ago

It seems that the local folder mounted contain too many files, and exceeded the maximum # of files that the auto-reloading program (inotify) allows. You can run following command to check the limit:

docker run --rm -t phpswoole/swoole cat /proc/sys/fs/inotify/max_user_watches

You can increase the limit by updating file /proc/sys/fs/inotify/max_user_watches in the Docker container.

nezamy commented 4 years ago

I tried to edit the file but I got this

echo 999999999999 > /proc/sys/fs/inotify/max_user_watches
bash: /proc/sys/fs/inotify/max_user_watches: Read-only file system

Is there any other way to work with Docker in development

deminy commented 4 years ago

Sorry my previous answer was wrong. To increase the limit, we need to update fs.inotify.max_user_watches on the host but not in the Docker container, since the container will just transparently share whatever is set on the host.

On Linux, we can set a new limit temporarily with following commands with sudo or use the root account:

sysctl fs.inotify.max_user_watches=999999
sysctl -p

On MacOS, it requires more steps than on Linux:

  1. We need to login to Docker host first. With Docker Desktop for Mac 2.3, I can do that by running command screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty.
  2. After login, run the two sysctl commands mentioned previously.
  3. Once done, please press button Ctrl-a d or Ctrl-a Ctrl-d to detach from the screen session.

Now we can run command docker run --rm -t phpswoole/swoole cat /proc/sys/fs/inotify/max_user_watches to see if the limit has been successfully changed or not. Please note that I tested it on MacOS only; ideally it should work for Linux as well.

I didn't try to make the changes permanently; if interested, please check GitLab page Increasing the amount of inotify watchers for more information.