Programmer-RD-AI commited on
Commit
625bcca
·
1 Parent(s): bbe4eea

add dokerifle

Browse files
Files changed (1) hide show
  1. Dockerfile +69 -0
Dockerfile ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use Node.js 18 Alpine for smaller image size
2
+ FROM node:18-alpine AS base
3
+
4
+ # Install dependencies only when needed
5
+ FROM base AS deps
6
+ # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
7
+ RUN apk add --no-cache libc6-compat
8
+ WORKDIR /app
9
+
10
+ # Install dependencies based on the preferred package manager
11
+ COPY package*.json pnpm-lock.yaml* ./
12
+ RUN \
13
+ if [ -f pnpm-lock.yaml ]; then \
14
+ corepack enable pnpm && pnpm i --frozen-lockfile; \
15
+ elif [ -f package-lock.json ]; then \
16
+ npm ci; \
17
+ else \
18
+ echo "Lockfile not found." && exit 1; \
19
+ fi
20
+
21
+ # Rebuild the source code only when needed
22
+ FROM base AS builder
23
+ WORKDIR /app
24
+ COPY --from=deps /app/node_modules ./node_modules
25
+ COPY . .
26
+
27
+ # Build the Next.js application
28
+ RUN \
29
+ if [ -f pnpm-lock.yaml ]; then \
30
+ corepack enable pnpm && pnpm run build; \
31
+ else \
32
+ npm run build; \
33
+ fi
34
+
35
+ # Create public directory if it doesn't exist
36
+ RUN mkdir -p ./public
37
+
38
+ # Production image, copy all the files and run next
39
+ FROM base AS runner
40
+ WORKDIR /app
41
+
42
+ ENV NODE_ENV=production
43
+ # Uncomment the following line in case you want to disable telemetry during runtime.
44
+ # ENV NEXT_TELEMETRY_DISABLED 1
45
+
46
+ RUN addgroup --system --gid 1001 nodejs
47
+ RUN adduser --system --uid 1001 nextjs
48
+
49
+ COPY --from=builder /app/public ./public
50
+
51
+ # Set the correct permission for prerender cache
52
+ RUN mkdir .next
53
+ RUN chown nextjs:nodejs .next
54
+
55
+ # Automatically leverage output traces to reduce image size
56
+ # https://nextjs.org/docs/advanced-features/output-file-tracing
57
+ COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
58
+ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
59
+
60
+ USER nextjs
61
+
62
+ # Expose port 3000 (Next.js default)
63
+ EXPOSE 3000
64
+
65
+ ENV PORT=3000
66
+ ENV HOSTNAME="0.0.0.0"
67
+
68
+ # Run the application
69
+ CMD ["node", "server.js"]