Files

48 lines
1.3 KiB
Docker
Raw Permalink Normal View History

# 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 . .
# Set environment for build to ensure server binds to all interfaces
ENV HOSTNAME="0.0.0.0"
ENV PORT="3000"
# Set API_INTERNAL_URL for build-time Next.js rewrites evaluation
ENV API_INTERNAL_URL="http://workclub-api:8080"
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 - bind to all interfaces (0.0.0.0) for external access
ENV HOSTNAME="0.0.0.0"
ENV PORT="3000"
CMD ["node", "server.js"]