Report this

What is the reason for this report?

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

Posted on April 2, 2021

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
``


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

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.

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

  1. grep -i memory /var/log/messages
  1. grep -i kill /var/log/messages

Regards, Alex

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.