skip to Main Content

I have the cheapest instance os AWS Lightsail (512 MB RAM, 1 vCPU, 20 GB SSD) with Ubuntu 20.04 and I’m trying to deploy a project with 5 containers (django, react, nginx, postgres, redis and celery) using docker-compose (which I manually installed).

The django build was successfull, however docker is returning a 137 error during the react build. It seems that one of the libraries I used has a depreceated dependency at node 14.16.1:

npm WARN deprecated [email protected]: Chokidar 2 will break on node v14+. 
Upgrade to chokidar 3 with 15x less dependencies.

npm WARN deprecated [email protected]: fsevents 1 will break on node v14+ and could be using insecure binaries. 
Upgrade to fsevents 2.

I don’t know if npm is trying to fix these issues by upgrading the packages, but this is taking a lot of time for docker to continue until it one of two things happen:

  • docker throws error 137;
The command '/bin/sh -c apk add --no-cache --virtual .gyp python make g++ && npm install && apk del .gyp' returned a non-zero code: 137
ERROR: Service 'react' failed to build : Build failed
  • I lost connection with my instance and couldn’t connect to it for hours. AWS returns the following error: UPSTREAM_NOT_FOUND [519]

The OOM problem is happening because I’m trying to build something that the machine will not support? Or can I adjust some configurations to make it work? How can I fix this?

Dockerfile:

###########
# BUILDER #
###########

FROM node:14.16.1-alpine3.10 as builder

WORKDIR /app/react

# install dependencies and avoid `node-gyp rebuild` errors
COPY ./package.json .
RUN apk add --no-cache --virtual .gyp 
    python 
    make 
    g++ 
    && npm install 
    && apk del .gyp

COPY . .

RUN npm run build


#########
# FINAL #
#########


FROM node:14.16.1-alpine3.10

WORKDIR /app/react

# install serve - deployment static server suggested by official create-react-app
RUN npm install -g serve

COPY --from=builder /app/react/build ./build

Thanks a lot!

2

Answers


  1. The 137 exit code is actually from the linux kernel, not from docker. It means your process ran out of memory and got killed. Probably lots of the processes that run during the build will use more than 512M of RAM maybe even one or two gigabytes. You should use an instance with more RAM and the issue should resolve itself.

    Login or Signup to reply.
  2. I am building react app and faced memory issue while building in docker linux machine. After Setting GENERATE_SOURCEMAP=false the docker build succeeded.

    "build": "GENERATE_SOURCEMAP=false react-scripts  --openssl-legacy-provider build",
    

    For more info on GENERATE_SOURCEMAP check here – https://create-react-app.dev/docs/advanced-configuration/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search