Update Dockerfile
This commit is contained in:
24
Dockerfile
24
Dockerfile
@@ -1,30 +1,32 @@
|
||||
# Stage 1: Build the React Application
|
||||
FROM node:20-slim AS builder
|
||||
# Using standard node:20 (not slim/alpine) to ensure build tools like python/make/g++ are present
|
||||
FROM node:20 AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package.json (and lock file if it exists) to install dependencies first
|
||||
# Copy package.json (and lock file if it exists)
|
||||
COPY package*.json ./
|
||||
|
||||
# Install all dependencies (including devDependencies for the build process)
|
||||
RUN npm install
|
||||
# Install dependencies using legacy-peer-deps to avoid version conflicts
|
||||
RUN npm install --legacy-peer-deps
|
||||
|
||||
# Copy the rest of the application source code
|
||||
COPY . .
|
||||
|
||||
# Build the frontend assets (Vite will output to /app/dist)
|
||||
# Build the frontend assets
|
||||
RUN npm run build
|
||||
|
||||
# Stage 2: Setup the Production Server (Node.js)
|
||||
FROM node:20-slim
|
||||
# Stage 2: Setup the Production Server
|
||||
# Using standard node:20 to ensure native modules (like pg/mysql drivers) install correctly
|
||||
FROM node:20
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package.json again for production dependencies
|
||||
COPY package*.json ./
|
||||
|
||||
# Install ONLY production dependencies (skips devDependencies like Vite/Typescript)
|
||||
RUN npm install --omit=dev
|
||||
# Install ONLY production dependencies
|
||||
RUN npm install --omit=dev --legacy-peer-deps
|
||||
|
||||
# Copy the built frontend assets from the 'builder' stage
|
||||
COPY --from=builder /app/dist ./dist
|
||||
@@ -32,11 +34,11 @@ COPY --from=builder /app/dist ./dist
|
||||
# Copy the server entry point
|
||||
COPY server.js ./
|
||||
|
||||
# Set environment variables (defaults)
|
||||
# Set environment variables
|
||||
ENV NODE_ENV=production
|
||||
ENV PORT=3000
|
||||
|
||||
# Expose the port the app runs on
|
||||
# Expose the port
|
||||
EXPOSE 3000
|
||||
|
||||
# Start the Node.js server
|
||||
|
||||
Reference in New Issue
Block a user