update dokcer

This commit is contained in:
smfahim25 2025-12-02 14:59:58 +06:00
parent b58ddac75b
commit e1994eb066
4 changed files with 45 additions and 12 deletions

6
.dockerignore Normal file
View file

@ -0,0 +1,6 @@
node_modules
.next
.git
.gitignore
README.md
.env*.local

View file

@ -1,21 +1,47 @@
# Step 1: Build FROM node:18-alpine AS base
FROM node:18-alpine AS builder
# Install dependencies only when needed
FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app WORKDIR /app
# Install dependencies
COPY package.json package-lock.json* ./
RUN npm ci
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . . COPY . .
RUN npm install
# Build the application
RUN npm run build RUN npm run build
# Step 2: Run # Production image, copy all the files and run next
FROM node:18-alpine FROM base AS runner
WORKDIR /app WORKDIR /app
ENV NODE_ENV production
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public COPY --from=builder /app/public ./public
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
EXPOSE 3000 # Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next
CMD ["npm", "start"] # Automatically leverage output traces to reduce image size
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3005
ENV PORT 3005
ENV HOSTNAME "0.0.0.0"
CMD ["node", "server.js"]

View file

@ -8,7 +8,7 @@ services:
dockerfile: Dockerfile dockerfile: Dockerfile
restart: always restart: always
ports: ports:
- "3000:3000" - "3005:3005"
networks: networks:
- coolify - coolify
environment: environment:

View file

@ -2,6 +2,7 @@ import type { NextConfig } from "next";
const nextConfig: NextConfig = { const nextConfig: NextConfig = {
/* config options here */ /* config options here */
output: "standalone",
images: { images: {
remotePatterns: [ remotePatterns: [
{ {