Docker config

This commit is contained in:
mukesh13
2025-06-16 18:39:44 +05:30
parent 4be1a13441
commit 776d69654d
3 changed files with 49 additions and 22 deletions

View File

@ -1,32 +1,61 @@
# Use the official Node.js 20 image as the base # syntax=docker.io/docker/dockerfile:1
FROM node:20-alpine
# Set working directory # Base stage for Node.js
FROM node:20-alpine AS base
# Stage 1: Install dependencies
FROM base AS deps
# Add libc6-compat for compatibility with some Node.js native modules
RUN apk add --no-cache libc6-compat
WORKDIR /app WORKDIR /app
# Install pnpm # Copy dependency files
RUN corepack enable && corepack prepare pnpm@latest --activate
# Copy only dependency files first
COPY package.json pnpm-lock.yaml* ./ COPY package.json pnpm-lock.yaml* ./
# Install dependencies with pnpm # Install pnpm and dependencies
RUN pnpm install --frozen-lockfile RUN corepack enable pnpm && pnpm install --frozen-lockfile
# Copy the rest of the application code # Stage 2: Build the Next.js app
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . . COPY . .
# Create a cache directory for Next.js # Create a cache directory for Next.js
RUN mkdir -p /app/.next/cache RUN mkdir -p /app/.next/cache
# Disable telemetry # Disable telemetry during build
ENV NEXT_TELEMETRY_DISABLED=1 ENV NEXT_TELEMETRY_DISABLED=1
# Build the Next.js application # Build the Next.js app
RUN pnpm build RUN corepack enable pnpm && pnpm run build
# Stage 3: Production image
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Create a non-root user
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy public assets
COPY --from=builder /app/public ./public
# Copy standalone output and static files
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# Copy the .next/cache for runtime caching (e.g., ISR)
COPY --from=builder --chown=nextjs:nodejs /app/.next/cache ./.next/cache
USER nextjs
# Expose port 3000
EXPOSE 3000 EXPOSE 3000
# Start the Next.js application ENV PORT=3000
CMD ["pnpm", "start", "-p", "3000"] ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]

View File

@ -1,4 +1,3 @@
version: '3.8'
services: services:
web: web:
build: build:

View File

@ -1,7 +1,6 @@
import type { NextConfig } from "next"; /** @type {import('next').NextConfig} */
const nextConfig = {
const nextConfig: NextConfig = { output: 'standalone',
/* config options here */
}; };
export default nextConfig; module.exports = nextConfig;