Back to Dev Tools
Dockerfile Generator
Generate optimized Dockerfiles for containerization
Options
Environment Variables
Dockerfile
# Build stage FROM node:18-alpine AS builder WORKDIR /app # Copy package files COPY package.json package-lock.json ./ # Install dependencies RUN npm ci # Copy source files COPY . . # Build the application RUN npm run build # Production stage FROM node:18-alpine AS runner WORKDIR /app # Environment variables ENV NODE_ENV=production # Create non-root user RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 appuser # Copy built files from builder COPY --from=builder /app/dist ./dist COPY --from=builder /app/node_modules ./node_modules COPY --from=builder /app/package.json ./package.json # Set ownership and switch to non-root user RUN chown -R appuser:nodejs /app USER appuser # Expose port EXPOSE 3000 # Start the application CMD ["npm", "start"]