feat: optimize Docker startup with Next.js standalone output and proper migrations
Some checks failed
Deploy with Docker Compose / deploy (push) Has been cancelled
Some checks failed
Deploy with Docker Compose / deploy (push) Has been cancelled
- Add `output: standalone` to next.config.js for faster cold start - Rebuild runner stage around standalone bundle (node server.js instead of pnpm start) - Replace prisma db push with prisma migrate deploy (proper migration workflow) - Remove npx/pnpm at runtime, use direct binary paths - Add HOSTNAME=0.0.0.0 for standalone server to listen on all interfaces - Fix next.config.js not copied in builder stage - Update README: pnpm instead of yarn, correct ports, full env vars documentation Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
23
Dockerfile
23
Dockerfile
@@ -17,7 +17,7 @@ COPY package.json pnpm-lock.yaml ./
|
||||
COPY prisma ./prisma
|
||||
|
||||
# Copy configuration files
|
||||
COPY tsconfig.json .eslintrc.json ./
|
||||
COPY tsconfig.json .eslintrc.json next.config.js ./
|
||||
COPY tailwind.config.ts postcss.config.js ./
|
||||
|
||||
# Install dependencies with pnpm using cache mount for store
|
||||
@@ -43,22 +43,20 @@ WORKDIR /app
|
||||
# Install OpenSSL (required by Prisma)
|
||||
RUN apk add --no-cache openssl libc6-compat
|
||||
|
||||
# Copy package files and prisma schema
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
COPY prisma ./prisma
|
||||
# Copy standalone output (server.js + minimal node_modules)
|
||||
COPY --from=builder /app/.next/standalone ./
|
||||
|
||||
# Enable pnpm
|
||||
RUN corepack enable && corepack prepare pnpm@9.0.0 --activate
|
||||
# Copy static assets and public directory
|
||||
COPY --from=builder /app/.next/static ./.next/static
|
||||
COPY --from=builder /app/public ./public
|
||||
|
||||
# Copy the entire node_modules from builder (includes Prisma Client)
|
||||
# Copy full node_modules for Prisma CLI (pnpm symlinks prevent cherry-picking)
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
|
||||
# Copy built application from builder stage
|
||||
COPY --from=builder /app/.next ./.next
|
||||
COPY --from=builder /app/public ./public
|
||||
COPY --from=builder /app/next-env.d.ts ./
|
||||
COPY --from=builder /app/tailwind.config.ts ./
|
||||
# Copy prisma schema and init scripts
|
||||
COPY prisma ./prisma
|
||||
COPY --from=builder /app/scripts ./scripts
|
||||
COPY package.json ./
|
||||
|
||||
# Copy entrypoint script
|
||||
COPY docker-entrypoint.sh ./
|
||||
@@ -76,6 +74,7 @@ USER nextjs
|
||||
# Set environment variables
|
||||
ENV NODE_ENV=production
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
ENV HOSTNAME="0.0.0.0"
|
||||
|
||||
# Expose the port the app runs on
|
||||
EXPOSE 3000
|
||||
|
||||
Reference in New Issue
Block a user