feat: implement multi-stage Docker build for optimized Next.js production deployment
This commit is contained in:
parent
5d3fd4fc06
commit
0bd850b40d
27
Dockerfile
27
Dockerfile
@ -1,5 +1,5 @@
|
|||||||
# Production-ready Dockerfile for Next.js
|
# Production-ready Dockerfile for Next.js
|
||||||
FROM node:20-alpine AS base
|
FROM node:20-alpine AS builder
|
||||||
|
|
||||||
# Set the working directory in the container
|
# Set the working directory in the container
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
@ -17,18 +17,31 @@ RUN npm ci
|
|||||||
COPY myfavstuff .
|
COPY myfavstuff .
|
||||||
|
|
||||||
# Build the Next.js application
|
# Build the Next.js application
|
||||||
RUN echo "--- Debugging Build Environment Variables ---" && \
|
RUN echo "--- Debugging Build Environment Variables (Builder Stage) ---" && \
|
||||||
echo "NEXT_PUBLIC_SUPABASE_URL as set in Dockerfile: ($NEXT_PUBLIC_SUPABASE_URL)" && \
|
echo "NEXT_PUBLIC_SUPABASE_URL: ($NEXT_PUBLIC_SUPABASE_URL)" && \
|
||||||
echo "NEXT_PUBLIC_SUPABASE_ANON_KEY as set in Dockerfile: ($NEXT_PUBLIC_SUPABASE_ANON_KEY)" && \
|
echo "NEXT_PUBLIC_SUPABASE_ANON_KEY: ($NEXT_PUBLIC_SUPABASE_ANON_KEY)" && \
|
||||||
echo "--- End Debugging --- " && \
|
echo "--- End Debugging --- " && \
|
||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
# Use a non-root user for security
|
# Use a non-root user for security
|
||||||
RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001
|
RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001
|
||||||
|
|
||||||
|
# Production stage
|
||||||
|
FROM node:20-alpine AS runner
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
|
COPY --from=builder /app/public ./public
|
||||||
|
# Next.js 15 uses a standalone output by default in the .next/standalone directory
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
|
|
||||||
USER nextjs
|
USER nextjs
|
||||||
|
|
||||||
# Expose port 3000 (default for Next.js)
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
# Command to run the application
|
ENV PORT 3000
|
||||||
CMD ["npm", "start"]
|
ENV HOSTNAME 0.0.0.0
|
||||||
|
|
||||||
|
CMD ["node", "server.js"]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user