Created
June 14, 2024 09:20
-
-
Save nghiepdev/fbd0d66c0a5af7a23fbad3c4ac1fb515 to your computer and use it in GitHub Desktop.
Dockerfile.next.js.example
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
# Stage 0 | |
FROM node:20-slim as base | |
LABEL maintainer="Nghiep <[email protected]>" | |
ENV PNPM_HOME="/pnpm" | |
ENV PATH="$PNPM_HOME:$PATH" | |
RUN corepack enable | |
RUN corepack prepare pnpm@9 --activate | |
ENV NEXT_TELEMETRY_DISABLED 1 | |
WORKDIR /app | |
COPY .npmrc package.json pnpm-lock.yaml pnpm-workspace.yaml cache-handler.mjs next.config.mjs ./ | |
# State 1 | |
FROM base as deps | |
COPY packages ./packages | |
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile --ignore-scripts --production | |
# Stage 2 | |
FROM base as builder | |
COPY packages ./packages | |
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile --ignore-scripts | |
COPY . . | |
ENV NODE_ENV production | |
RUN pnpm build | |
# Stage 3 | |
FROM base as runner | |
ARG NEXT_PUBLIC_VERSION | |
ENV NEXT_PUBLIC_VERSION $NEXT_PUBLIC_VERSION | |
ENV NODE_ENV production | |
ENV PORT 3000 | |
COPY --from=builder /app/.env* ./ | |
COPY --from=builder /app/.next ./.next | |
COPY --from=builder /app/public ./public | |
COPY --from=deps /app/node_modules ./node_modules | |
EXPOSE $PORT | |
CMD ["pnpm", "start"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment