Question

Out of memory on building simple Next app

Posted September 17, 2021 223 views
DockerDigitalOcean App PlatformNext.js

I spent a day getting out of memory error building Next app from Dockerfile. It is a small app with a few pages. However, removing Dockerfile and let the app built with Buildpack results in successful deployment

  • What is the memory limit when build with Dockerfile and how to increase it?
  • Is there an example Dockerfile for Next app?
  • Does the container size and plan (Basic/Pro) matter?

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

Hi @chatpong,

Please find the answers to your queries inline.

What is the memory limit when build with Dockerfile and how to increase it?
–> In app platform there is 8GB of RAM available during build. Currently we do not support the increase of resources during build phase for any of our users. However, that is under discussion and might get updated in the future.

Is there an example Dockerfile for Next app?
–> Here’s a sample git repo for deploying a Next app using a Dockerfile. I have tested it out on App Platform.
https://github.com/tahafatimaDO/next-Dockerfile

Does the container size and plan (Basic/Pro) matter?
–> The container size and plan doesn’t matter during the build phase. It only comes into play during the deploy and run time.

Cheers,
Taha Fatima

  • Hi @tahafatima,

    Thanks a lot for your answer. I have tried your sample repo and it built fine. However, I have 2 projects that fail to build with app platform but succeed using GitLab runner.

    I don’t think it’s out of memory issue if the builder has 8 GB of RAM. It could be something specific in my projects and I will open a ticket to the support team. Will update this post once I know the cause

    Cheers,

I have contacted the support team and one thing I know from them is that the App platform only has 8GB of RAM/Disk space combined available during build. So, it is not just RAM but I have to be careful about disk space also.

Spent a few days trying to tweak the Dockerfile. As Docker takes snapshot for each build step, I though I should make each layer as small as I could. So, I did install and build in one go and below is the Dockerfile I successfully deployed to the App platform

FROM node:alpine
WORKDIR /app
COPY . ./
RUN yarn install --frozen-lockfile \
    && yarn build \
    && rm -rf node_modules \
    && yarn install --production --prefer-offline \
    && yarn cache clean --all
CMD [ "yarn", "start" ]

Hope this helps everyone who is facing the same problem