Increase watchers in node docker image
Asked Answered
C

4

11

Need to increase watchers in docker image, as it fails on expo publish with the error

[11:39:08] Error: ENOSPC: System limit for number of file watchers reached, watch '/__w/mevris-client-app-products/mevris-client-app-products/node_modules/update-notifier/node_modules/camelcase'
[11:39:08]     at FSWatcher.start (internal/fs/watchers.js:165:26)
[11:39:08]     at Object.watch (fs.js:1258:11)
[11:39:08]     at NodeWatcher.watchdir (/__w/mevris-client-app-products/mevris-client-app-products/node_modules/metro/node_modules/sane/src/node_watcher.js:159:22)
[11:39:08]     at Walker.<anonymous> (/__w/mevris-client-app-products/mevris-client-app-products/node_modules/metro/node_modules/sane/src/common.js:109:31)
[11:39:08]     at Walker.emit (events.js:198:13)
[11:39:08]     at /__w/mevris-client-app-products/mevris-client-app-products/node_modules/walker/lib/walker.js:69:16
[11:39:08]     at go$readdir$cb (/__w/mevris-client-app-products/mevris-client-app-products/node_modules/@react-native-community/cli/node_modules/graceful-fs/graceful-fs.js:187:14)
[11:39:08]     at FSReqWrap.args [as oncomplete] (fs.js:140:20)

Added following lines to Dockerfile

RUN echo "fs.inotify.max_user_instances=524288" >> /etc/sysctl.conf && sysctl -p

results in this error when build sysctl: setting key "fs.inotify.max_user_watches": Read-only file system

I need to use that docker image in Github Actions

Dockerfile

FROM node:10

RUN echo "fs.inotify.max_user_instances=524288" >> /etc/sysctl.conf
RUN echo "fs.inotify.max_user_watches=524288" >> /etc/sysctl.conf
RUN echo "fs.inotify.max_queued_events=524288" >> /etc/sysctl.conf

RUN apt-get -qq update && apt-get -qq -y install bzip2

RUN yarn global add @bluebase/cli && bluebase plugins:add @bluebase/cli-expo && bluebase plugins:add @bluebase/cli-web

RUN bluebase plugins

RUN npm i -g expo-cli

COPY entrypoint.sh /entrypoint.sh

ENTRYPOINT ["sh", "/entrypoint.sh"]
Clouded answered 25/10, 2019 at 13:5 Comment(2)
can you post the whole Dockerfile?Foul
Added DockerfileClouded
U
7

I had the same issue running Docker on Mac OSX (not docker-for-mac).

Based on the premise that the sysclt settings are shared with the kernel host, I fixed the problem doing ssh to the docker-machine (boot2docker) and changing the settings there.

$ docher-machine ssh
$ echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
$ sudo sysctl -p
Ultraviolet answered 27/1, 2020 at 7:44 Comment(0)
U
3

From this issues/24 and this issues/628

You need to increase the fs.inotify.max_user_watchesparameter on the host. For example you can create a configuration file in /etc/sysctl.d. Example /etc/sysctl.d/crashplan.conf with content:

fs.inotify.max_user_watches = 1048576

You can not change at build time is it will not affect and also it will not allow you during build time.

The workaround is to avoid getting this error, set it during run time in the entrypoint.

FROM node:10.16

# set inotify and start the node application, replace yar with your command
RUN echo "#!/bin/sh \n\
echo "fs.inotify.max_user_watches before update" \n\
cat /etc/sysctl.conf\n\
echo "______________________________________________updating inotify ____________________________________" \n\
echo fs.inotify.max_user_watches=524288 | tee -a /etc/sysctl.conf && sysctl -p \n\
echo "updated value is" \n\
cat /etc/sysctl.conf | grep fs.inotify \n\
exec yarn start:dev \
" >> /usr/local/bin/entrypoint.sh

RUN chmod +x /usr/local/bin/entrypoint.sh

# EXPOSE TARGET PORT
EXPOSE 3001
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

Unscientific answered 25/10, 2019 at 13:41 Comment(3)
I tried this, but I still get sysctl: setting key "fs.inotify.max_user_watches": Read-only file system on container start.Tawanda
Make your container privileged. If you are using k8s deployment set this spec.template.spec.containers.securityContext: trueNosepiece
If Docker container used in github Actions, which option will be good mine getting permission denied.Waligore
H
0

I ran into this recently when trying to serve a node application from a mounted drive through docker-compose. No matter how high I set max_user_watchers, I kept getting that error "Internal watch failed: ENOSPC: System limit for number of file watchers reached, watch..."

In my case, it was coming from nodemon, and all I had to do was add a -L (for legacyWatch) flag. There might be something similar for your case, or perhaps provides a hint of another approach.

In some networked environments (such as a container running nodemon reading across a mounted drive), you will need to use the legacyWatch: true which enables Chokidar's polling.

Via the CLI, use either --legacy-watch or -L for short: nodemon -L

https://www.npmjs.com/package/nodemon
about half way down, or page search for "Application isn't restarting"

I am not familiar enough with how watchers, polling, and docker mounted drives all work together (or not) to explain why. Not yet anyway.

Hydrops answered 24/4, 2023 at 20:15 Comment(0)
Q
-1

try to echo "fs.inotify.max_user_watches=524288" >> /etc/sysctl.conf

source: whats-wrong-with-my-simple-react-docker-image

PS. Maybe it is a problem of a parent host? Check param on the host befor run docker. This work to me.

Qualify answered 5/2, 2021 at 12:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.