Created
November 25, 2024 07:08
-
-
Save aybabtme/ac4b4156b8a098ca486832c3bf93fadf to your computer and use it in GitHub Desktop.
dockerfile for self-hosting next.js
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:22-alpine AS base | |
# deps | |
FROM base AS deps | |
WORKDIR /usr/src/app | |
RUN apk add --no-cache libc6-compat | |
COPY package.json package-lock.json* ./ | |
RUN npm ci | |
# builder | |
FROM base AS builder | |
WORKDIR /usr/src/app | |
COPY --from=deps /usr/src/app/node_modules ./node_modules | |
COPY . . | |
RUN npm run build | |
# server | |
FROM base AS server | |
WORKDIR /usr/src/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 /usr/src/app/public ./public | |
RUN mkdir .next | |
RUN chown nextjs:nodejs .next | |
COPY --from=builder --chown=nextjs:nodejs /usr/src/app/.next/standalone ./ | |
COPY --from=builder --chown=nextjs:nodejs /usr/src/app/.next/static ./.next/static | |
USER nextjs | |
EXPOSE 3000 | |
ENV PORT=3000 | |
ENV HOSTNAME="0.0.0.0" | |
ENTRYPOINT ["node", "server.js"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment