34 lines
598 B
Docker
34 lines
598 B
Docker
# Stage 1: Build
|
|
FROM node:20-alpine AS builder
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy package.json and package-lock.json (or yarn.lock)
|
|
COPY package*.json ./
|
|
|
|
# Install dependencies
|
|
RUN npm ci
|
|
|
|
# Copy the rest of the app
|
|
COPY . .
|
|
|
|
# Build the app (React/Next/etc.)
|
|
RUN npm run build
|
|
|
|
# Stage 2: Production image
|
|
FROM node:20-alpine
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy only build output and dependencies
|
|
COPY --from=builder /app/package*.json ./
|
|
COPY --from=builder /app/node_modules ./node_modules
|
|
COPY --from=builder /app/build ./build
|
|
|
|
# Expose port
|
|
EXPOSE 3000
|
|
|
|
# Default command
|
|
CMD ["npm", "start"]
|