fix(frontend): use multi-stage docker build to be self-contained [32788f42]
This commit is contained in:
@@ -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
|
||||
|
||||
# Set working directory to nginx's default static file directory
|
||||
# Set working directory
|
||||
WORKDIR /usr/share/nginx/html
|
||||
|
||||
# Remove default Nginx static assets
|
||||
# Remove default Nginx assets
|
||||
RUN rm -rf ./*
|
||||
|
||||
# Copy the built React app from the builder stage
|
||||
# The React app is built using `npm run build` which creates a `dist` directory
|
||||
COPY ./dist .
|
||||
# Copy built assets from the builder stage
|
||||
COPY --from=builder /app/dist .
|
||||
|
||||
# Expose port 80
|
||||
EXPOSE 80
|
||||
|
||||
# Command to start Nginx (default command of the base image)
|
||||
# Start Nginx
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
|
||||
Reference in New Issue
Block a user