Prevent node from running out of memory in a docker build that a 600 MB memory limit Prevent node from running out of memory in a docker build that a 600 MB memory limit docker docker

Prevent node from running out of memory in a docker build that a 600 MB memory limit


Can you change your base image? I think that can help. This memory leak problem was in NodeJS v10 and v12, just use latest LTS version (v14) and also alpine version of the image.


when using a GC language like JS or Java you have the most popular part of the language memory component which is the heap but you also have another part that is being used when running or building an application, that is the stack.

In any way, I would suggest monitoring the docker build memory usage with docker stats or any other monitoring tool you prefer as well as the react-scripts build memory usage if you use the --expose-gc option (in reference to this thread) and check the docker build logs for any spikes in usage. Running the react-scripts build command outside could help to try and determine what memory requirements the build process actually requires and setting it to it plus some buffer in the container after.

It could be that you're limiting your heap size for nothing to half of the container total memory capacity you've set (600MB), try increasing the heap memory capacity while keeping the containers one the same (increase --max_old_space_size while keeping --memory at 600MB).

Anbother option that seems to help in this and that case is to upgrade node base image to node:lts or node:14.16.0 (are the same image as of the time of writing this).