1
+ FROM node:lts-alpine AS base
2
+
1
3
# Install dependencies only when needed
2
- FROM node:lts-alpine AS deps
3
- RUN corepack enable
4
+ FROM base AS deps
4
5
5
6
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
6
7
RUN apk add --no-cache libc6-compat
@@ -16,12 +17,11 @@ RUN \
16
17
fi
17
18
18
19
# Rebuild the source code only when needed
19
- FROM node:lts-alpine AS builder
20
- RUN corepack enable
20
+ FROM base AS builder
21
21
WORKDIR /app
22
22
23
- COPY . .
24
23
COPY --from=deps /app/node_modules ./node_modules
24
+ COPY . .
25
25
26
26
# Add env for production
27
27
# COPY .docker/production/.env.local .env.local
@@ -89,32 +89,42 @@ ENV TINA_SEARCH_TOKEN $TINA_SEARCH_TOKEN
89
89
ARG NEXT_PUBLIC_SLOT_URL
90
90
ENV NEXT_PUBLIC_SLOT_URL $NEXT_PUBLIC_SLOT_URL
91
91
92
- RUN pnpm run build
92
+ RUN \
93
+ if [ -f yarn.lock ]; then yarn run build; \
94
+ elif [ -f package-lock.json ]; then npm run build; \
95
+ elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
96
+ else echo "Lockfile not found." && exit 1; \
97
+ fi
93
98
94
99
# Production image, copy all the files and run next
95
- FROM node:lts-alpine AS runner
96
- RUN corepack enable
100
+ FROM base AS runner
97
101
WORKDIR /app
98
102
103
+ ENV NODE_ENV production
99
104
# Uncomment the following line in case you want to disable telemetry during runtime.
100
105
# ENV NEXT_TELEMETRY_DISABLED 1
101
106
102
107
RUN addgroup --system --gid 1001 nodejs
103
108
RUN adduser --system --uid 1001 nextjs
104
109
110
+ COPY --from=builder /app/public ./public
111
+
112
+ # Set the correct permission for prerender cache
113
+ RUN mkdir .next
114
+ RUN chown nextjs:nodejs .next
115
+
105
116
# Automatically leverage output traces to reduce image size
106
117
# https://nextjs.org/docs/advanced-features/output-file-tracing
118
+ COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
119
+ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
120
+ COPY --from=builder --chown=nextjs:nodejs /app/appInsight-api.js ./
107
121
108
122
USER nextjs
109
123
110
124
EXPOSE 3000
111
125
112
- ENV NODE_ENV production
113
126
ENV PORT 3000
114
127
115
- COPY --from=builder --chown=nextjs:nodejs /app/public ./public
116
- COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
117
- COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
118
- COPY --from=builder --chown=nextjs:nodejs /app/appInsight-api.js ./
119
-
120
- CMD ["node" , "--require" , "./appInsight-api.js" , "server.js" ]
128
+ # server.js is created by next build from the standalone output
129
+ # https://nextjs.org/docs/pages/api-reference/next-config-js/output
130
+ CMD HOSTNAME="0.0.0.0" node --require ./appInsight-api.js server.js
0 commit comments