
Multi-Stage Docker Builds for Fullstack React + Node Apps
I used to ship fullstack apps as 1.2GB Docker images. Node modules, build tools, source maps, dev dependencies -- all crammed into one layer. It worked, but pulling that image on a $5 VPS with 1GB RAM was painful. Multi-stage builds cut that to ~180MB. Here's the exact setup I use for Vite + Fastify apps with Prisma, including the Traefik reverse proxy config for automatic SSL. The Problem with Single-Stage Builds A naive Dockerfile looks like this: FROM node:22-alpine WORKDIR /app COPY . . RUN npm install RUN npm run build EXPOSE 3000 CMD ["node", "dist/server.js"] This image includes everything: TypeScript compiler, Vite, all dev dependencies, source files, node_modules with 400+ packages you only need at build time. The result is 1GB+ and slow to deploy. The Multi-Stage Approach The idea is simple: use one stage to build, another to run. The build stage has all the tools. The production stage copies only the compiled output. Here's the complete Dockerfile for a Vite frontend + Fasti
Continue reading on Dev.to React
Opens in a new tab



