Question

Out of memory error when running nginx react and node with docker

Posted April 2, 2021 2.6k views
NginxNode.jsDockerReact

I am using the 5 dollar plan to host mongodb, nginx, react node through docker and docker compose. The problem I have is that it keeps giving me

The build failed because the process exited too early. This probably means the system ran out of memory or someone called `kill -9` on the process.

This image building starts with the backend and then react where this error occurs. The specific line it occurs is at


Step 5/9 : RUN yarn build
 ---> Running in e12af022dcf1
yarn run v1.22.5
$ react-scripts build
Creating an optimized production build...

I am using the multi-stage docker build for react and nginx

FROM node:alpine as build
WORKDIR /usr/app
COPY ./client .
RUN yarn install
RUN yarn build

FROM nginx:alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY ./nginx/nginx.conf /etc/nginx/nginx.conf
COPY --from=build /usr/app/build /usr/share/nginx/html
``

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
2 answers

Hello there,

I will recommend you to inspect the memory usage using top , htop or sar and see if the memory usage is indeed high during the process.

You can also check the logs and see if there were killed processes and if the server was out of memory. In order to do that you can run the following commands

  • grep -i memory /var/log/messages
  • grep -i kill /var/log/messages

Regards,
Alex

I had the very same problem. Though we are using kubernetes (not docker compose), but the issue may be the same. So, in my case it was the problem of too few resources allocated to the pod through kubernetes config files. After I added a bit more CPU and memory it started to build.
It was this:

resources:
  limits:
    memory: '1024Mi'
    cpu: '1'
  requests:
    memory: '64Mi'
    cpu: '100m'

And I changed that to:

resources:
  limits:
    memory: '4096Mi'
    cpu: '2'
  requests:
    memory: '128Mi'
    cpu: '300m'

Hopefully it will be useful to somebody.