Implements Tasks 23 & 24: Backend and Frontend Dockerfiles Backend Dockerfiles: - Dockerfile.dev: Development with dotnet watch hot reload - Base: sdk:10.0, installs dotnet-ef tool - Layer caching: csproj files copied before source - Entry: dotnet watch run with --no-restore - Dockerfile: Production multi-stage build - Build stage: sdk:10.0, restore + build + publish - Runtime stage: aspnet:10.0-alpine (~110MB) - Health check: /health/live endpoint - Non-root: USER app (built-in) Frontend Dockerfiles: - Dockerfile.dev: Development with Bun hot reload - Base: node:22-alpine, installs Bun globally - Layer caching: package.json + bun.lock before source - Command: bun run dev - Dockerfile: Production standalone 3-stage build - Deps stage: Install with --frozen-lockfile - Build stage: bun run build → standalone output - Runner stage: node:22-alpine with non-root nextjs user - Copies: .next/standalone, .next/static, public - Health check: Node.js HTTP GET to port 3000 - Entry: node server.js (~240MB) All Dockerfiles use layer caching optimization and security best practices. Note: Docker build verification skipped (Docker daemon not running).
41 lines
1.0 KiB
Docker
41 lines
1.0 KiB
Docker
# Multi-stage production Dockerfile for Next.js standalone
|
|
|
|
# Stage 1: Dependencies
|
|
FROM node:22-alpine AS deps
|
|
RUN npm install -g bun
|
|
WORKDIR /app
|
|
COPY package.json bun.lock ./
|
|
RUN bun install --frozen-lockfile
|
|
|
|
# Stage 2: Build
|
|
FROM node:22-alpine AS build
|
|
RUN npm install -g bun
|
|
WORKDIR /app
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
COPY . .
|
|
RUN bun run build
|
|
|
|
# Stage 3: Runtime
|
|
FROM node:22-alpine AS runner
|
|
WORKDIR /app
|
|
|
|
# Create non-root user
|
|
RUN adduser --system --uid 1001 nextjs
|
|
|
|
# Copy standalone build output
|
|
COPY --from=build --chown=nextjs:nodejs /app/.next/standalone ./
|
|
COPY --from=build --chown=nextjs:nodejs /app/.next/static ./.next/static
|
|
COPY --from=build --chown=nextjs:nodejs /app/public ./public
|
|
|
|
# Switch to non-root user
|
|
USER nextjs
|
|
|
|
EXPOSE 3000
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
CMD node -e "require('http').get('http://localhost:3000', (r) => {if (r.statusCode !== 200) throw new Error(r.statusCode)})"
|
|
|
|
# Start standalone server
|
|
CMD ["node", "server.js"]
|