Skip to content

Instantly share code, notes, and snippets.

@aybabtme
Created November 25, 2024 07:08
Show Gist options
  • Select an option

  • Save aybabtme/ac4b4156b8a098ca486832c3bf93fadf to your computer and use it in GitHub Desktop.

Select an option

Save aybabtme/ac4b4156b8a098ca486832c3bf93fadf to your computer and use it in GitHub Desktop.

Revisions

  1. aybabtme created this gist Nov 25, 2024.
    33 changes: 33 additions & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    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"]