1- # Install dependencies only when needed
2- FROM node:20-slim AS deps
3- # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
1+ FROM node:20-slim AS base
42RUN apt-get update && \
53 apt-get install ca-certificates curl libjemalloc-dev -y --no-install-recommends && \
64 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
713WORKDIR /app
814
9- # Install dependencies based on the preferred package manager
10- COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .env ./
11- COPY .npmrc ./.npmrc
12-
13-
14-
15-
16- RUN \
17- if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
18- elif [ -f package-lock.json ]; then npm ci; \
19- elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \
20- else echo "Lockfile not found." && exit 1; \
21- fi
22-
23-
24- # Rebuild the source code only when needed
25- FROM node:20-slim AS builder
26- WORKDIR /app
27- COPY --from=deps /app/node_modules ./node_modules
28- COPY . .
29-
30- # Next.js collects completely anonymous telemetry data about general usage.
31- # Learn more here: https://nextjs.org/telemetry
32- # Uncomment the following line in case you want to disable telemetry during the build.
33- # ENV NEXT_TELEMETRY_DISABLED 1
34-
35- RUN CI=true yarn build
36-
37- # If using npm comment out above and use below instead
38- # RUN npm run build
39-
40- # Production image, copy all the files and run next
41- FROM node:20-slim AS runner
42- WORKDIR /app
43-
44- ENV NODE_ENV=production
45- # Uncomment the following line in case you want to disable telemetry during runtime.
46- # ENV NEXT_TELEMETRY_DISABLED 1
47-
48- RUN addgroup --system --gid 1001 nodejs
49- RUN adduser --system --uid 1001 nextjs
50-
51- COPY --from=builder /app/public ./public
52-
53- # Automatically leverage output traces to reduce image size
54- # https://nextjs.org/docs/advanced-features/output-file-tracing
55- COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
56- COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
57-
58- 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
5918
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
6023EXPOSE 3000
61-
6224ENV PORT=3000
63-
64- CMD ["node" , "server.js" ]
25+ ENV HOSTNAME= "0.0.0.0"
26+ CMD ["node" , "server.js" ]
0 commit comments