My-Weekly-ToDo-List/Dockerfile
mARTin 02a8c2a0b4 chore: Production Dockerfile, deploy script, dev port 3001
- Multi-stage Dockerfile: build stage + slim production runner
- Runs `next build` + `next start` instead of `npm run dev`
- Dev server on port 3001 to avoid conflict with production on 3000
- Deploy script with version bumping and health checks
- Explicit .env.production for docker-compose
- Updated .gitignore and .dockerignore

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 22:07:46 +01:00

53 lines
1.2 KiB
Docker

# ---- Build stage ----
FROM node:18-slim AS builder
WORKDIR /app
# Install OpenSSL for Prisma
RUN apt-get update && apt-get install -y openssl && rm -rf /var/lib/apt/lists/*
COPY package*.json ./
RUN npm ci
COPY . .
# Generate Prisma client
RUN npx prisma generate
# Build the Next.js application
RUN npm run build
# ---- Production stage ----
FROM node:18-slim AS runner
WORKDIR /app
ENV NODE_ENV=production
# Install OpenSSL for Prisma and curl for healthcheck
RUN apt-get update && apt-get install -y openssl curl && rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy built output and dependencies
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/next.config.js ./
# Create logs directory
RUN mkdir -p /app/logs && chown -R nextjs:nodejs /app
USER nextjs
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD curl -f http://localhost:3000/api/auth/session || exit 1
CMD ["npm", "run", "start"]