39 lines
881 B
Docker
39 lines
881 B
Docker
# Stage 1: Builder
|
|
FROM node:20-alpine AS builder
|
|
|
|
# Enable pnpm
|
|
RUN corepack enable
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy dependency files and install dependencies
|
|
COPY package.json pnpm-lock.yaml ./
|
|
RUN pnpm install --frozen-lockfile
|
|
|
|
# Copy the rest of the application source code
|
|
COPY . .
|
|
|
|
# Run the build command
|
|
RUN pnpm run build
|
|
|
|
# ---
|
|
|
|
# Stage 2: Runner
|
|
FROM node:20-alpine AS runner
|
|
WORKDIR /app
|
|
|
|
# Create a non-root user for security
|
|
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
|
|
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 creates a server.js file that is the entrypoint
|
|
CMD ["node", "server.js"] |