Web Configurator
Generate optimized multi-stage Dockerfiles for web applications
Configuration
⚠️ Requires output: "standalone" in next.config.js
Dockerfile
1# Generated by DockerFit (https://tools.eastondev.com/docker)2# Next.js + pnpm + Node 203# Optimized multi-stage build ✓45# ========== Stage 1: Install dependencies ==========6FROM node:20-alpine AS deps78# Enable pnpm9RUN corepack enable pnpm1011WORKDIR /app1213# Copy package files14COPY package.json pnpm-lock.yaml ./1516# Install dependencies with cache17RUN --mount=type=cache,id=pnpm,target=/pnpm/store \18 pnpm install --frozen-lockfile1920# ========== Stage 2: Build ==========21FROM node:20-alpine AS builder2223RUN corepack enable pnpm2425WORKDIR /app2627# Copy dependencies from deps stage28COPY --from=deps /app/node_modules ./node_modules29COPY . .3031# Disable Next.js telemetry32ENV NEXT_TELEMETRY_DISABLED=13334# Build the application35RUN pnpm build3637# ========== Stage 3: Production ==========38FROM node:20-alpine AS runner3940WORKDIR /app4142# Set production environment43ENV NODE_ENV=production44ENV NEXT_TELEMETRY_DISABLED=145ENV HOSTNAME="0.0.0.0"4647# Create non-root user for security48RUN addgroup --system --gid 1001 nodejs && \49 adduser --system --uid 1001 appuser5051# Copy standalone build (requires output: 'standalone' in next.config.js)52COPY --from=builder --chown=appuser:nodejs /app/.next/standalone ./53COPY --from=builder --chown=appuser:nodejs /app/.next/static ./.next/static54COPY --from=builder --chown=appuser:nodejs /app/public ./public5556USER appuser5758EXPOSE 30005960CMD ["node", "server.js"]
Recommended Platform
Railway - Developer-Friendly Deployment
Professional container hosting. Deploy from Dockerfile instantly. $20 free credit for new users.
- $20 free credit on signup
- Dockerfile & GitHub auto-deploy
- True pay-as-you-go pricing
- Built-in PostgreSQL, Redis & more
Tips
- • Enable standalone mode in Next.js for minimal image size
- • Use
pnpmfor faster installs and smaller node_modules - • Add
.dockerignoreto exclude node_modules and .next
Build & Run
Build and run your containerized app:
docker build -t my-app . && docker run -p 3000:3000 my-app