fix(frontend): use multi-stage docker build to be self-contained [32788f42]

This commit is contained in:
2026-03-20 13:52:33 +00:00
parent 961dbf1348
commit 6b8e146c4a

View File

@@ -1,18 +1,34 @@
# Use a lightweight Nginx image to serve the React app # Stage 1: Build the React application
FROM node:18-alpine AS builder
WORKDIR /app
# Copy package.json and package-lock.json
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy the rest of the application source code
COPY . .
# Build the application
RUN npm run build
# Stage 2: Serve the application with Nginx
FROM nginx:alpine FROM nginx:alpine
# Set working directory to nginx's default static file directory # Set working directory
WORKDIR /usr/share/nginx/html WORKDIR /usr/share/nginx/html
# Remove default Nginx static assets # Remove default Nginx assets
RUN rm -rf ./* RUN rm -rf ./*
# Copy the built React app from the builder stage # Copy built assets from the builder stage
# The React app is built using `npm run build` which creates a `dist` directory COPY --from=builder /app/dist .
COPY ./dist .
# Expose port 80 # Expose port 80
EXPOSE 80 EXPOSE 80
# Command to start Nginx (default command of the base image) # Start Nginx
CMD ["nginx", "-g", "daemon off;"] CMD ["nginx", "-g", "daemon off;"]