Update Dockerfile
This commit is contained in:
parent
d7eb8b23f7
commit
78734c15d1
26
Dockerfile
26
Dockerfile
@ -1,8 +1,9 @@
|
||||
# ---- 1) Install deps (cached) ----------------------------------------------
|
||||
# ---- 1) Install deps --------------------------------------------------------
|
||||
FROM node:20-alpine AS deps
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
RUN npm ci
|
||||
# Works even if there is no package-lock.json
|
||||
RUN npm install
|
||||
|
||||
# ---- 2) Build the Next.js app ----------------------------------------------
|
||||
FROM node:20-alpine AS builder
|
||||
@ -12,27 +13,26 @@ COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
# ---- 3) Runtime: copy standalone output, run as non-root -------------------
|
||||
# ---- 3) Runtime -------------------------------------------------------------
|
||||
FROM node:20-alpine AS runner
|
||||
WORKDIR /app
|
||||
|
||||
# Environment
|
||||
ENV NODE_ENV=production
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
ENV PORT=3000
|
||||
|
||||
# Non-root user
|
||||
# run as non-root
|
||||
RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001
|
||||
|
||||
# Copy only what's needed to run the server
|
||||
# - .next/standalone includes server.js and minimal node_modules
|
||||
# - .next/static and public are needed for assets
|
||||
# Copy the built app and runtime deps
|
||||
COPY --from=builder /app/.next ./.next
|
||||
COPY --from=builder /app/public ./public
|
||||
COPY --from=builder /app/.next/standalone ./
|
||||
COPY --from=builder /app/.next/static ./.next/static
|
||||
COPY --from=builder /app/package*.json ./
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
|
||||
# Trim dev deps from node_modules (optional but nice)
|
||||
RUN npm prune --omit=dev
|
||||
|
||||
# Expose Next.js port
|
||||
EXPOSE 3000
|
||||
|
||||
USER 1001
|
||||
CMD ["node", "server.js"]
|
||||
CMD ["npm", "start"]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user