I deployed n8n on Docker and to my surprise, it uses 10GB of Virtual Memory. It would not usually be a problem, but I’m running n8n in a Docker-in-Docker setup (it’s complicated, short answer is it’s the easiest way to run Vanilla Docker on TrueNAS SCALE) my host OS reports the 10GB as actually used!
So I went looking for options to reduce the virtual memory:
setting NODE_OPTIONS=--max-old-space-size=4096 environment variable did not work
overriding the Docker entrypoint but I could not pass NODE_OPTIONS environment variable and --max-old-space-size is not a valid n8n option
Is there any way to reduce the virtual memory size I am not aware of?
Thanks!
Something like docker run -it --rm --name n8n -p 5678:5678 -v ~/.n8n:/home/node/.n8n -m 320m n8nio/n8n:0.206.1 would limit your n8n container to 320 MB. You can verify this by running docker stats:
I’ve already tried this (though with deploy.resources.limits.memory and deploy.resources.reservations.memory as I use docker-compose 3) but the limit does not seem to be honoured.
# docker stats
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
6eddda58f0a0 n8n 0.00% 182MiB / 512MiB 35.54% 146kB / 38.9kB 0B / 0B 12
# top
Load average: 0.22 0.26 0.26 1/1917 984816
PID PPID USER STAT VSZ %VSZ CPU %CPU COMMAND
10042501004184 1000 S 10.4g 31% 8 0% node /usr/local/bin/n8n
I checked again and it is not working exactly as set in limits
When I set mem limit to 512 - it still sets it to 650, but at least it is not using up all RAM as it was before
I just rebooted my NAS, the RAM was freed before I started the n8n container. After I started it up, it reported 10GB of virtual memory usage even though it had memory limits in place
As far as I understand top isn’t able to list what is happening in a container if you run it on a host unless you are using docker exec to run top within the container from the host maybe.
If you are just running top on the host though I would quickly run n8n --version to see if you get a result, At the moment it kind of feels like it is running on the host somewhere outside of docker.
Maybe a quick sudo ps -ef | grep n8n would show something.