From 0d79536895b79773083336e93988c900e8d44bf5 Mon Sep 17 00:00:00 2001 From: mukeshs Date: Fri, 10 Oct 2025 00:03:28 +0530 Subject: [PATCH] Docker update --- DockerFile | 35 ++++++++++++++++------------------- docker-compose.yml | 14 ++++++++------ next.config.ts | 3 ++- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/DockerFile b/DockerFile index ac80fd6..bd8eb7a 100644 --- a/DockerFile +++ b/DockerFile @@ -1,21 +1,22 @@ # Stage 1: Build FROM node:18-alpine AS builder -# Set working directory WORKDIR /app -# Copy package files and install dependencies +# Copy package files COPY package.json package-lock.json ./ -RUN npm install --production -# Copy the rest of the app +# Install ALL dependencies (including dev dependencies for build) +RUN npm ci + +# Copy source code COPY . . -# Pass build-time environment variable +# Build arguments ARG NEXT_PUBLIC_API_URL ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} -# Build the Next.js app +# Build the app RUN npm run build # Stage 2: Run @@ -23,23 +24,19 @@ FROM node:18-alpine AS runner WORKDIR /app -# Copy built app from builder -COPY --from=builder /app/.next ./.next -COPY --from=builder /app/public ./public -COPY --from=builder /app/package.json ./package.json -COPY --from=builder /app/package-lock.json ./package-lock.json -COPY --from=builder /app/next.config.js ./next.config.js +# Set to production +ENV NODE_ENV=production -# Install only production dependencies -RUN npm install --production +# Copy necessary files +COPY --from=builder /app/public ./public +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static # Expose port EXPOSE 3000 -# Runtime environment variables -ENV NODE_ENV=production -ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} -ENV HOST=0.0.0.0 +ENV PORT=3000 +ENV HOSTNAME="0.0.0.0" # Start the app -CMD ["npm", "start"] +CMD ["node", "server.js"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 2915cfe..6551e31 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,13 +2,15 @@ version: "3.9" services: nextjs: - build: . + build: + context: . + args: + NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL} container_name: cmc_nextjs_pro ports: - "9012:3000" - env_file: - - .env # <-- tell Docker to use the .env file + environment: + - NODE_ENV=production + - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} restart: unless-stopped - volumes: - - .:/app - - /app/node_modules + # Remove the volumes - they overwrite your build! \ No newline at end of file diff --git a/next.config.ts b/next.config.ts index 11ec9e5..2c7c1e8 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,6 +1,7 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { + /* config options here */ images: { remotePatterns: [ @@ -22,7 +23,7 @@ const nextConfig: NextConfig = { pathname: '/api/files/images/**', } ], - domains: ['localhost'], + }, };