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:lts-alpine AS base
|
||||||
FROM node:20-alpine AS builder
|
|
||||||
|
# Stage 1: Install dependencies
|
||||||
|
FROM base AS deps
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
# Enable Corepack
|
COPY package.json yarn.lock ./
|
||||||
RUN corepack enable
|
RUN corepack enable yarn && yarn install --immutable
|
||||||
|
|
||||||
# Set Yarn to the latest stable version
|
# Stage 2: Build the application
|
||||||
RUN yarn set version stable
|
FROM base AS builder
|
||||||
|
WORKDIR /app
|
||||||
COPY package.json package-lock.json ./
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
RUN yarn install
|
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN yarn build
|
RUN corepack enable yarn && yarn build
|
||||||
|
|
||||||
# Stage 2: Create the production image
|
# Stage 3: Production server
|
||||||
FROM node:20-alpine AS runner
|
FROM base AS runner
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
# Optional: disable Next.js telemetry
|
COPY --from=builder /app/.next/standalone ./
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
COPY --from=builder /app/.next/static ./.next/static
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
CMD ["node", "server.js"]
|
||||||
ENV PORT=3000
|
|
||||||
# The standalone output generates a server.js file that starts the app
|
|
||||||
CMD ["node", "server.js"]
|
|
||||||
Reference in New Issue
Block a user