Files
cmc_frontend/DockerFile
2026-02-03 20:12:51 +05:30

50 lines
1.0 KiB
Plaintext

# Stage 1: Build
FROM node:18-alpine AS builder
WORKDIR /app
# Build arguments - MUST be before COPY to be available during build
ARG NEXT_PUBLIC_API_URL
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
# Copy package files
COPY package.json package-lock.json ./
# Install ALL dependencies (including dev dependencies for build)
RUN npm ci
# Copy source code
COPY . .
# Build the app
RUN npm run build
# Stage 2: Run
FROM node:18-alpine AS runner
WORKDIR /app
# Set to production
ENV NODE_ENV=production
# Runtime environment variable
ARG NEXT_PUBLIC_API_URL
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
# Copy necessary files
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
# Create cache directory with wide-open permissions
RUN mkdir -p .next/cache/images && \
chmod -R 777 .next/cache
# Expose port
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
# Start the app (running as root to avoid permission issues)
CMD ["node", "server.js"]