new new dockerfile
Some checks failed
Main / build-and-push-docker-image (20.x) (push) Failing after 3m13s
Some checks failed
Main / build-and-push-docker-image (20.x) (push) Failing after 3m13s
This commit is contained in:
46
Dockerfile
46
Dockerfile
@@ -1,38 +1,24 @@
|
||||
# Stage 1: Build the Next.js application
|
||||
FROM node:20-alpine AS builder
|
||||
FROM node:lts-alpine AS base
|
||||
|
||||
# Stage 1: Install dependencies
|
||||
FROM base AS deps
|
||||
WORKDIR /app
|
||||
# Enable Corepack
|
||||
RUN corepack enable
|
||||
COPY package.json yarn.lock ./
|
||||
RUN corepack enable yarn && yarn install --immutable
|
||||
|
||||
# Set Yarn to the latest stable version
|
||||
RUN yarn set version stable
|
||||
|
||||
COPY package.json package-lock.json ./
|
||||
RUN yarn install
|
||||
# Stage 2: Build the application
|
||||
FROM base AS builder
|
||||
WORKDIR /app
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
RUN yarn build
|
||||
RUN corepack enable yarn && yarn build
|
||||
|
||||
# Stage 2: Create the production image
|
||||
FROM node:20-alpine AS runner
|
||||
# Stage 3: Production server
|
||||
FROM base AS runner
|
||||
WORKDIR /app
|
||||
|
||||
ENV NODE_ENV=production
|
||||
# Optional: disable Next.js telemetry
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
|
||||
# Create a non-root user
|
||||
RUN addgroup --system --gid 1001 nodejs
|
||||
RUN adduser --system --uid 1001 nextjs
|
||||
USER nextjs
|
||||
|
||||
# Copy the standalone output from the builder stage
|
||||
COPY --from=builder /app/public ./public
|
||||
# Automatically leverage output traces to reduce image size
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||
COPY --from=builder /app/.next/standalone ./
|
||||
COPY --from=builder /app/.next/static ./.next/static
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
ENV PORT=3000
|
||||
# The standalone output generates a server.js file that starts the app
|
||||
CMD ["node", "server.js"]
|
||||
CMD ["node", "server.js"]
|
||||
Reference in New Issue
Block a user