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