This commit is contained in:
41
Dockerfile
41
Dockerfile
@@ -1,41 +1,26 @@
|
||||
# 1. Install dependencies and build the project
|
||||
FROM node:20-alpine AS builder
|
||||
|
||||
# Install node and yarn
|
||||
RUN apk add --no-cache nodejs npm
|
||||
|
||||
# Enable Corepack
|
||||
# --- Stage 1: Dependencies ---
|
||||
FROM node:20-alpine AS dependencies
|
||||
RUN corepack enable
|
||||
|
||||
# Install latest yarn
|
||||
RUN corepack prepare yarn@stable --activate
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json yarn.lock ./
|
||||
RUN yarn install --immutable
|
||||
|
||||
# --- Stage 2: Builder ---
|
||||
FROM node:20-alpine AS builder
|
||||
RUN corepack enable
|
||||
RUN corepack prepare yarn@stable --activate
|
||||
WORKDIR /app
|
||||
COPY --from=dependencies /app .
|
||||
COPY . .
|
||||
RUN yarn build # Replace with your build command
|
||||
|
||||
# Next.js standalone output copies only necessary files
|
||||
RUN yarn build
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
|
||||
# 2. Production stage: use a minimal base image
|
||||
# --- Stage 3: Runner ---
|
||||
FROM node:20-alpine AS runner
|
||||
RUN corepack enable
|
||||
RUN corepack prepare yarn@stable --activate
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app/build ./build
|
||||
COPY --from=dependencies /app/.yarn ./.yarn
|
||||
|
||||
# Set the environment variable for standalone output directory
|
||||
ENV NODE_ENV=production
|
||||
# Next.js will copy the standalone files to /app/standalone/.next
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
|
||||
COPY --from=builder /app/public ./public
|
||||
COPY --from=builder /app/.next/standalone ./
|
||||
COPY --from=builder /app/.next/static ./.next/static
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["node", "server.js"]
|
||||
CMD ["yarn", "start"] # Replace with your start command
|
||||
|
||||
Reference in New Issue
Block a user