Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase watchers in node docker image

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"]
like image 213
Hashim Avatar asked Oct 25 '19 13:10

Hashim


2 Answers

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
like image 126
Matias Avatar answered Oct 08 '22 22:10

Matias


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"]

like image 26
Adiii Avatar answered Oct 08 '22 20:10

Adiii