feat: Add Dockerfile for production deployment
This commit is contained in:
parent
8eaaf26512
commit
b7ddedb2e8
1 changed files with 41 additions and 0 deletions
41
Dockerfile
Normal file
41
Dockerfile
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
# ---- 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" ]
|
Loading…
Reference in a new issue