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