Change inotify.max_user_instances limit in Docker container

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-07 02:53:30

问题


I am trying to change inotify.max_user_instances setting for docker env on the level of Dockerfile. I am trying to do it because I am receiving this error:

Application startup exception: System.IO.IOException: The configured user limit (128) on the number of inotify instances has been reached.

I already use:

 .AddJsonFile($"appsettings.json", optional: true, reloadOnChange: false);

I as well tried to use custom "WebHost.CreateDefaultBuilder(args)", because it was pointed out that it uses reloadOnChange: true with the same file.

Tried as well running in dockerfile:

RUN sysctl -w fs.inotify.max_user_watches=1048576
RUN echo fs.inotify.max_user_watches=1048576 | tee -a /etc/sysctl.conf && sysctl -p

But it was pointed out that it is impossible to run from that context.

Is there possibility to change those sysctl settings from the stage of docker image build/deployment? I am a little lost in this.

If it helps, application is using .net core 2.2


回答1:


Is there possibility to change those sysctl settings from the stage of docker image build

No. The output of the image build is only a filesystem image, plus some metadata about the default environment variables and command to run when you docker run the image. It does not include running processes, sysctl values, or anything else.

Remember that sysctl settings are usually global kernel-level settings; since all Docker containers share the host's kernel, they usually share the same sysctl values. (Since containers also generally have isolated filesystems, watching for filesystem changes via inotify isn't really a common use case; if there's a substantial change in the code or other image context, it's more common to rebuild the image and then delete and recreate the container.)

There are a limited set of values you can change via docker run --sysctl but these do not include the inotify values. The only way to change this value is to run sysctl, as root, on the host, outside of Docker.




回答2:


I had this same issue on Docker for Mac and indeed the setting lives on the host rather than the container. The host is not Mac OS but the Linux VM running under the covers. To change the setting there you need to access it from the terminal:

screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty

If you get a blank screen hit Enter once and you should get a $docker-desktop prompt. Apply your setting by typing the command:

sysctl -w fs.inotify.max_user_watches=1048576

To exit the screen Ctrl-a d or Ctrl-a Ctrl-d. See the screen manual # Detach.

Unfortunately the setting is not persisted and resets after a reboot because the underlying file system is readonly. If anyone can tell me how to do that I'd greatly appreciate it.



来源:https://stackoverflow.com/questions/57220658/change-inotify-max-user-instances-limit-in-docker-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!