41 lines
1 KiB
Text
41 lines
1 KiB
Text
|
# ---- Stage 1: Build the React App ----
|
||
|
# Use an official Node.js image as the base for building
|
||
|
FROM node:20-alpine AS build
|
||
|
|
||
|
# Set the working directory inside the container
|
||
|
WORKDIR /app
|
||
|
|
||
|
# Copy package.json and package-lock.json to leverage Docker layer caching
|
||
|
COPY package*.json ./
|
||
|
|
||
|
# Install all dependencies
|
||
|
RUN npm install
|
||
|
|
||
|
# Copy the rest of the application source code
|
||
|
COPY . .
|
||
|
|
||
|
# Build the application for production
|
||
|
# This runs "vite build" and creates the /app/dist folder
|
||
|
RUN npm run build
|
||
|
|
||
|
# ---- Stage 2: Serve the App in a Production Environment ----
|
||
|
# Use a smaller, secure Node.js image for the final container
|
||
|
FROM node:20-alpine
|
||
|
|
||
|
WORKDIR /app
|
||
|
|
||
|
# We only need package.json to install the 'serve' package
|
||
|
COPY package*.json ./
|
||
|
|
||
|
# Install ONLY production dependencies (in this case, 'serve')
|
||
|
RUN npm install --omit=dev
|
||
|
|
||
|
# Copy the built static files from the 'build' stage
|
||
|
COPY --from=build /app/dist ./dist
|
||
|
|
||
|
# Expose the port that 'serve' will run on
|
||
|
EXPOSE 3000
|
||
|
|
||
|
# The command to start the web server
|
||
|
# This runs "serve -s dist"
|
||
|
CMD [ "npm", "start" ]
|