Some checks failed
Main / build-and-push-docker-image (20.x) (push) Failing after 2m52s
39 lines
987 B
Docker
39 lines
987 B
Docker
# Stage 1: Build the Next.js application
|
|
FROM node:20-alpine AS builder
|
|
WORKDIR /app
|
|
# Enable Corepack
|
|
RUN corepack enable
|
|
|
|
# Set Yarn to the latest stable version
|
|
RUN yarn set version stable
|
|
|
|
COPY package.json package-lock.json ./
|
|
RUN yarn install
|
|
COPY . .
|
|
RUN yarn build
|
|
|
|
# Stage 2: Create the production image
|
|
FROM node:20-alpine 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
|
|
|
|
EXPOSE 3000
|
|
|
|
ENV PORT=3000
|
|
# The standalone output generates a server.js file that starts the app
|
|
CMD ["node", "server.js"]
|