1- # Install dependencies only when needed
2- FROM node:lts-alpine AS deps
3- # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
4- RUN apk add --no-cache libc6-compat curl
1+ FROM node:20-slim AS base
2+ RUN apt-get update && \
3+ apt-get install ca-certificates curl libjemalloc-dev -y --no-install-recommends && \
4+ rm -rf /var/lib/apt/lists/*
5+ # set environment variable to preload JEMalloc
6+ ENV LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libjemalloc.so.2"
7+ # set GC time, set arenas number, set background_thread run GC
8+ ENV MALLOC_CONF=dirty_decay_ms:1000,narenas:2,background_thread:true
9+ ENV PNPM_HOME="/pnpm"
10+ ENV PATH="$PNPM_HOME:$PATH"
11+ RUN corepack enable
12+ COPY . /app
513WORKDIR /app
614
7- # Install dependencies based on the preferred package manager
8- COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc ./
9- RUN \
10- if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
11- elif [ -f package-lock.json ]; then npm ci; \
12- elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \
13- else echo "Lockfile not found." && exit 1; \
14- fi
15-
16-
17- # Rebuild the source code only when needed
18- FROM node:lts-alpine AS builder
19- WORKDIR /app
20- COPY --from=deps /app/node_modules ./node_modules
21- COPY . .
22-
23- # Next.js collects completely anonymous telemetry data about general usage.
24- # Learn more here: https://nextjs.org/telemetry
25- # Uncomment the following line in case you want to disable telemetry during the build.
26- # ENV NEXT_TELEMETRY_DISABLED 1
27-
28- RUN CI=true yarn build
29-
30- # If using npm comment out above and use below instead
31- # RUN npm run build
32-
33- # Production image, copy all the files and run next
34- FROM node:lts-alpine AS runner
35- WORKDIR /app
36-
37- ENV NODE_ENV=production
38- # Uncomment the following line in case you want to disable telemetry during runtime.
39- # ENV NEXT_TELEMETRY_DISABLED 1
40-
41- RUN addgroup --system --gid 1001 nodejs
42- RUN adduser --system --uid 1001 nextjs
43-
44- COPY --from=builder /app/public ./public
45-
46- # Automatically leverage output traces to reduce image size
47- # https://nextjs.org/docs/advanced-features/output-file-tracing
48- COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
49- COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
50-
51- USER nextjs
15+ FROM base AS build
16+ RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm i --frozen-lockfile
17+ RUN CI=true pnpm build
5218
19+ FROM base
20+ COPY --from=build /app/.next/standalone ./
21+ COPY --from=build /app/public ./public
22+ COPY --from=build /app/.next/static ./.next/static
5323EXPOSE 3000
54-
5524ENV PORT=3000
56-
57- CMD ["node" , "server.js" ]
25+ ENV HOSTNAME= "0.0.0.0"
26+ CMD ["node" , "server.js" ]
0 commit comments