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 20
3# Optimized multi-stage build ✓
4
5# ========== Stage 1: Install dependencies ==========
6FROM node:20-alpine AS deps
7
8# Enable pnpm
9RUN corepack enable pnpm
10
11WORKDIR /app
12
13# Copy package files
14COPY package.json pnpm-lock.yaml ./
15
16# Install dependencies with cache
17RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
18 pnpm install --frozen-lockfile
19
20# ========== Stage 2: Build ==========
21FROM node:20-alpine AS builder
22
23RUN corepack enable pnpm
24
25WORKDIR /app
26
27# Copy dependencies from deps stage
28COPY --from=deps /app/node_modules ./node_modules
29COPY . .
30
31# Disable Next.js telemetry
32ENV NEXT_TELEMETRY_DISABLED=1
33
34# Build the application
35RUN pnpm build
36
37# ========== Stage 3: Production ==========
38FROM node:20-alpine AS runner
39
40WORKDIR /app
41
42# Set production environment
43ENV NODE_ENV=production
44ENV NEXT_TELEMETRY_DISABLED=1
45ENV HOSTNAME="0.0.0.0"
46
47# Create non-root user for security
48RUN addgroup --system --gid 1001 nodejs && \
49 adduser --system --uid 1001 appuser
50
51# 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/static
54COPY --from=builder --chown=appuser:nodejs /app/public ./public
55
56USER appuser
57
58EXPOSE 3000
59
60CMD ["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
Get $20 Free

Tips

  • • Enable standalone mode in Next.js for minimal image size
  • • Use pnpm for faster installs and smaller node_modules
  • • Add .dockerignore to 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