Created
August 18, 2024 08:05
-
-
Save sajanv88/ae353b78ea79296ab949a265cac46475 to your computer and use it in GitHub Desktop.
Nextjs multi stage docker and pnpm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM node:21.7.3-alpine AS deps | |
RUN apk add --no-cache libc6-compat | |
ENV PNPM_HOME="/pnpm" | |
ENV PATH="$PNPM_HOME:$PATH" | |
RUN corepack enable | |
WORKDIR /app | |
COPY package.json pnpm-lock.yaml ./ | |
RUN pnpm install --frozen-lockfile | |
FROM deps AS builder | |
WORKDIR /app | |
COPY --from=deps /app/node_modules ./node_modules | |
COPY . . | |
ENV NEXT_TELEMETRY_DISABLED 1 | |
RUN pnpm build | |
FROM builder AS dev | |
WORKDIR /app | |
ENV NODE_ENV production | |
ENV NEXT_TELEMETRY_DISABLED 1 | |
RUN addgroup --system --gid 1001 nodejs | |
RUN adduser --system --uid 1001 nextjs | |
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next | |
COPY --from=builder /app/node_modules ./node_modules | |
COPY --from=builder /app/package.json ./package.json | |
USER nextjs | |
EXPOSE 4001 | |
ENV PORT 4001 | |
CMD ["pnpm", "start"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment