FROM node:20-bullseye AS base # 1. Install dependencies only when needed FROM base AS deps WORKDIR /app # Install dependencies based on the preferred package manager COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ RUN yarn install # # 2. Rebuild the source code only when needed FROM base AS builder WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . # This will do the trick, use the corresponding env file for each environment. RUN yarn workspace server install RUN yarn server:prod # 3. Production image, copy all the files and run next FROM base AS runner WORKDIR /app ENV NODE_ENV=production # RUN addgroup -g 1001 -S nodejs; COPY --from=builder /app/server/build ./ # Automatically leverage output traces to reduce image size # https://nextjs.org/docs/advanced-features/output-file-tracing COPY --from=builder /app/server/node_modules ./node_modules COPY --from=builder /app/server/package.json ./package.json EXPOSE 4000 3928 ENV PORT 4000 ENV APPDATA /app/data CMD ["node", "main.js"]