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