48 lines
1.3 KiB
Docker
48 lines
1.3 KiB
Docker
# Production-ready Dockerfile for Next.js
|
|
FROM node:20-alpine AS builder
|
|
|
|
# Set the working directory in the container
|
|
WORKDIR /app
|
|
|
|
ENV NODE_ENV=production
|
|
|
|
# Copy package.json and package-lock.json from the 'myfavstuff' subdirectory
|
|
COPY myfavstuff/package.json myfavstuff/package-lock.json* ./
|
|
|
|
# Install dependencies
|
|
# Using npm ci for cleaner installs based on package-lock.json
|
|
RUN npm ci
|
|
|
|
# Copy the rest of your app's source code from the 'myfavstuff' subdirectory
|
|
COPY myfavstuff .
|
|
|
|
# Build the Next.js application
|
|
RUN echo "--- Debugging Build Environment Variables (Builder Stage) ---" && \
|
|
echo "NEXT_PUBLIC_SUPABASE_URL: ($NEXT_PUBLIC_SUPABASE_URL)" && \
|
|
echo "NEXT_PUBLIC_SUPABASE_ANON_KEY: ($NEXT_PUBLIC_SUPABASE_ANON_KEY)" && \
|
|
echo "--- End Debugging --- " && \
|
|
npm run build
|
|
|
|
# Use a non-root user for security
|
|
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
|
|
|
|
EXPOSE 3000
|
|
|
|
ENV PORT 3000
|
|
ENV HOSTNAME 0.0.0.0
|
|
|
|
CMD ["node", "server.js"]
|