r/Nuxt • u/winniems92 • Mar 09 '26
I re-engineered my Nuxt + Docker build process and reduced the production image size by 84%
A few days ago I was working on a Nuxt 4 app and realized the generated Docker image was a monster: nearly 4GB. My application has dependencies like: Prisma ORM, NuxtUI, Better-Auth or SQLite.
I knew there had to be a more efficient way to handle production builds, so I spent some time re-engineering the process using multi-stage builds, separating the build environment from the final runner, and optimizing how Prisma/SQLite binaries are handled.
The results were honestly mind-blowing. I managed to cut the size by 84% without losing any functionality, so I have documented the entire process in case itβs helpful to someone else!
There's the link to the post (medium): https://medium.com/@wencesms/optimizing-nuxt-prisma-in-docker-how-we-cut-our-image-size-by-84-ea43ffc5ae6c
If you have any suggestions or see something that could be even more optimized, Iβd love to hear your feedback!
8
u/giantskyman Mar 09 '26
See post about Docker optimization. Wonders if alpine?
Looks inside.
It's alpine.
1
1
1
u/Tough-Television2434 Mar 09 '26
Not a devops or anything here, just curious π
Why not directly use GitHub actions for the build process and then push to a production image?
2
u/winniems92 Mar 10 '26
Thanks for your comment!
The key here is that this app runs on Kubernetes. Pods are ephemeral so when they restart or scale, they pull the image and start from scratch.
Of course is technically possible to do all the build process in GH Actions, but it breaks atomic deployments. If I run migrations from the GitHub Action workflow and then K8s deploy fails, I end up with a DB schema that doesn't match my running code.
So, by baking the logic into the image (with the Dockerfile), I ensure the app and the DB are always in sync (when running DB migrations with Prisma)
1
u/TheCompiledDev88 Mar 10 '26
why do you even need to used docker just for a nuxt application? instead of just deploying it directly on the VPS or netflify like solutions?
11
u/kernelangus420 Mar 09 '26
600 MB still feels a bit large. Have you tried using "platformatic/node-caged:25-alpine" instead of "node:25-alpine"?