Files
drb-frontend/Dockerfile
2025-05-25 23:20:48 -04:00

51 lines
1.6 KiB
Docker

# Stage 1: Install dependencies
FROM node:22-alpine AS deps
WORKDIR /app
# Install dependencies based on your package manager
# If you use npm:
COPY package.json package-lock.json ./
RUN npm ci
# If you use yarn:
# COPY package.json yarn.lock ./
# RUN yarn install --frozen-lockfile
# Stage 2: Build the Next.js application (production build)
FROM node:22-alpine AS builder
WORKDIR /app
# Copy dependencies from the 'deps' stage
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Build the Next.js application for production
ENV NODE_ENV production
RUN npm run build
# Stage 3: Run the Next.js application (flexible for dev and prod)
FROM node:22-alpine AS runner
WORKDIR /app
# Copy necessary files for both development and production
COPY --from=builder /app/src/public ./public
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
# If you are using `output: 'standalone'` in next.config.js, uncomment the following:
# ENV NEXT_SHARP_PATH=/usr/local/lib/node_modules/sharp
# COPY --from=builder /app/.next/standalone ./
# COPY --from=builder /app/.next/static ./.next/static
# COPY --from=builder /app/public ./public # Already copied above, but keep if standalone specific
# Expose the port Next.js runs on (default is 3000)
EXPOSE 3000
# Argument to set NODE_ENV at runtime
ARG NODE_ENV=production
ENV NODE_ENV ${NODE_ENV}
# Command to run the Next.js application
# This will run 'npm run dev' if NODE_ENV is 'development', otherwise 'npm start' (production)
CMD ["sh", "-c", "if [ \"$NODE_ENV\" = \"development\" ]; then npm run dev; else npm start; fi"]