Next.js Discord

Discord Forum

Dockerizing Nextjs

Unanswered
Asian black bear posted this in #help-forum
Open in Discord
Asian black bearOP
I want some thoughts on best practices when working on nextjs with docker. My stack is nextjs, postgres, and prisma as my ORM. I want to deploy to a docker container. As this is my first time containerizing an application I have some questions.

- Should the container only be used for prod? i.e running npm run build, then npm run start
- Alternatively, should I run my postgres in a container, and develop through my host machine connecting to it?
- If thats not best practice, what is the best way to set up a dockerfile/compose.yml to allow for development AND production. There seems to be controversial opinions on this online, what do you guys think

I apologize if some of my information is incorrect, I am still learning about the process. But my goal is to be able to develop/hot reload/database migrations, and then deploy to a container with an optimized build whenever I like.

Thanks!

3 Replies

Next has some docs on docker deployments, and to be honest, for all of the hate Next.js gets about being "vercel only", I found the docker deployment to be a BREEZE, and our apps run perfectly in production with no tinkering
@Luke https://nextjs.org/docs/app/building-your-application/deploying#docker-image
Blanc de Hotot
How do you deal with env variables when using Docker with NextJS?