Containerizing a Next.js App with Paketo Buildpacks #300
Replies: 6 comments 10 replies
-
@paketo-buildpacks/nodejs-maintainers can you advise please? My takeaways from that thread are that you probably need to use the Node.js buildpack (rather than Web Servers), and set the |
Beta Was this translation helpful? Give feedback.
-
I agree with @sophiewigmore. Unless you have used the option to build the site completely statically in Next.js (I'm not a Next.js expert but I believe that is an option not the default), you would need to use the https://github.com/paketo-buildpacks/nodejs, however I would suggest that you use the existing builder - https://github.com/paketo-buildpacks/builder-jammy-full versus specifying build pack. |
Beta Was this translation helpful? Give feedback.
-
I search on these errors and they seem to match problems people have been having:
It seem to happen if I use some of the default next.js example related to docker so don't think those have anything to do with using a buildpack. The suggestion to resolve seems to be: "build": "NODE_ENV=production next build", with the NODE_ENV=production being the part that fixes it. Not sure how that makes any sense, but seems to be the consensus on how to work around. |
Beta Was this translation helpful? Give feedback.
-
Next.js seems to be a many headed complicated thing. I think the closest use case to building with buildpacks in their examples are the ones using docker. Those include a different configuration from the example shown above. I created a new sample using npx create-next-app --example with-docker myapp Trying to build that resulted in the problem that work work around seems to be adding NODE_ENV=production, so I added that to the build command in the package.json Because the examples are to be run with docker they also don't include a start script line in the package.json so I added: "start": "node /workspace/.next/standalone/server.js" I derived that from how the application would have been started when the docker container was started. with that the package.json looked like {
"private": true,
"scripts": {
"dev": "next dev",
"build": "NODE_ENV=production next build",
"start": "node /workspace/.next/standalone/server.js"
},
"dependencies": {
"next": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
} I then built with: pack build testit --builder paketobuildpacks/builder-jammy-full and ran with docker run -p3000:3000 -it testit /bin/bash and the application ran properly. |
Beta Was this translation helpful? Give feedback.
-
One of the key differences between the examples using docker is that
@Itsdevashishgupta my suggestion is that you start with the docker example and build up your application from that as it seems to work ok with the paketo builder. |
Beta Was this translation helpful? Give feedback.
-
We also had to set I found that I could not create the optimized standalone app when building with paketo buildpacks because the This doesn't mean you can use buildpacks to build nextjs apps, but it does mean the standalone output is essentially ignored. |
Beta Was this translation helpful? Give feedback.
-
Hi everyone,
I’m Devashish Gupta, a developer working on a Next.js app, and I’m interested in containerizing it using Paketo buildpacks. I believe this could be valuable for efficient deployment and scalability.
Objective:
I’m looking to gather insights, best practices, and potential challenges in containerizing a Next.js app using Paketo buildpacks.
Context:
My Next.js app is a portfolio website (github repo: https://github.com/Itsdevashishgupta/raph_www). I need to ensure it’s containerized effectively for different environments.
Discussion Points:
Base Image: is there any changes required in stack
Environment Variables: do i need to provide any other env
Your Progress:
So far, I’ve tried
pack build frontend-app --buildpack paketo-buildpacks/web-servers
--env BP_NODE_RUN_SCRIPTS=build
--env BP_WEB_SERVER=nginx
--env BP_WEB_SERVER_ROOT=.next
but I encountered issue
docker run -it -p 3000:3000 --env PORT=3000 frontend-app
nginx 404 not found
So I’m looking for more detailed guidance.
Question:
What are the best practices for a containerized Next.js app?
Thank you in advance for your input! I’ll compile a summary of the responses and share it with the community.
Best regards,
Devashish Gupta
Beta Was this translation helpful? Give feedback.
All reactions