Limit memory 4GB when run Docker Images

I run Docker image in CircleCi.
When i restore mongodb it throw error exceed memory limit.
In the memory-usage.txt, CircleCI is running a lot of nodejs which increase memory.

PID RSS %CPU COMMAND 2260 176864 0.0 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --log-error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock 28033 149268 6.2 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28027 149264 6.2 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28038 147392 6.2 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28071 146856 6.4 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28123 145852 6.0 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28152 145800 5.9 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28133 145724 5.9 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28128 145708 6.0 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28153 145688 5.9 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28138 145544 5.9 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28178 145436 6.0 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28168 145328 6.0 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28032 145104 6.3 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28087 143904 6.3 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28183 143436 6.1 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28057 143284 6.4 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28062 141140 6.1 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28173 140544 6.2 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28043 140044 6.0 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28103 140036 6.2 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28112 140024 6.1 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28072 139748 6.1 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28118 139688 6.1 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28052 139568 6.2 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28077 138868 6.1 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28117 138352 6.1 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28093 138220 6.1 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28086 138172 6.1 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28158 137608 6.0 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28143 137464 6.0 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28163 137020 6.0 /usr/local/bin/node /home/nodejs/app/src/server/index.js 28098 136936 6.0 /usr/local/bin/node /home/nodejs/app/src/server/index.js 12592 108244 15.5 /usr/bin/docker daemon -s btrfs -D 27810 43020 1.7 npm 27858 41112 1.9 node ./src/server/index.js 27763 37312 0.9 mongod 18543 32904 0.3 /usr/lib/erlang/erts-5.10.4/bin/beam.smp -Bd -K true -A 4 -- -root /usr/lib/erlang -progname erl -- -home /var/lib/couchdb -- -noshell -noinput -os_mon start_memsup false start_cpu_sup false disk_space_check_interval 1 disk_almost_full_threshold 1 -sasl errlog_type error -couch_ini /etc/couchdb/default.ini /etc/couchdb/local.ini -s couch 39 20068 0.0 Xvfb :99 -screen 0 1280x1024x24 2407 16884 0.0 /usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.5/main -c config_file=/etc/postgresql/9.5/main/postgresql.conf 2683 16580 0.0 /usr/lib/postgresql/9.6/bin/postgres -D /var/lib/postgresql/9.6/main -c config_file=/etc/postgresql/9.6/main/postgresql.conf 27795 15892 0.1 docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8080 -container-ip 172.19.0.4 -container-port 8080 27747 13992 0.1 docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 27017 -container-ip 172.19.0.2 -container-port 27017 27838 8232 0.5 bash -c cd "/home/ubuntu/stacc-server/" mongorestore -d spikaenterprise features/support/db 27751 7844 0.3 redis-server *:6379 28440 7368 0.0 bash -c cd "/home/ubuntu/stacc-server/" mongorestore -d spikaenterprise features/support/db 28451 6848 0.0 bash -c cd "/home/ubuntu/stacc-server/" mongorestore -d spikaenterprise features/support/db 1417 4560 0.0 xfwm4 --daemon 2765 4024 0.0 sshd: ubuntu [priv]

Could i stop nodejs or do something to fix that issue?

Any luck with this?

I have a similar problem. When executing ā€œnpm testā€ the process is killed (without actually running any test) and the memory dump says 32 node.js procs were running using all the memory.

Hello @jpiqueras, @huytran,

Do you have a link to a build you can share so that we can take a look?

Hey @zzak,

For my case I posted the problem and the solution in here:

Basically jest is not detecting the number of cpus of the container but from underlying machine. This makes it create lots of threads.

I imagine something similar is happening for the case described here.

1 Like

Thank you @jpiqueras for posting your solution!!