puffin-app/Dockerfile
Matt 6e2b841d9e
All checks were successful
Build and Push Docker Images / docker (push) Successful in 2m12s
Fix API routes 404 - Remove incorrect .next/server copy
The previous fix incorrectly copied .next/server which conflicts
with Next.js standalone mode. Standalone is self-contained and
already includes compiled API routes internally.

Root cause: Next.js output:'standalone' creates a self-contained
.next/standalone directory that already contains all compiled API
routes. Copying .next/server separately creates path conflicts that
break the server's route resolution.

Official Next.js standalone pattern only requires copying:
- .next/standalone (contains server.js and routes)
- .next/static (static assets)
- public (public files)

Fixes: API routes returning 404 in production
2025-11-03 13:12:15 +01:00

38 lines
844 B
Docker

# Build Stage
FROM node:20-alpine AS build
WORKDIR /app
# Copy package files and install dependencies
COPY package*.json ./
RUN npm ci
# Copy the rest of the app
COPY . .
# Build Next.js app (standalone mode)
# All environment variables are runtime-configurable via .env or docker-compose
RUN npm run build
# Production Stage - Next.js standalone server
FROM node:20-alpine
WORKDIR /app
# Copy standalone server files from build stage
COPY --from=build /app/.next/standalone ./
COPY --from=build /app/.next/static ./.next/static
COPY --from=build /app/public ./public
# Expose port 3000
EXPOSE 3000
# Set environment to production
ENV NODE_ENV=production
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
# Start Next.js server
# Runtime environment variables (NEXT_PUBLIC_*) can be passed via docker-compose or -e flags
CMD ["node", "server.js"]