docker files updated
This commit is contained in:
41
app/Dockerfile
Normal file
41
app/Dockerfile
Normal file
@@ -0,0 +1,41 @@
|
||||
# Use the argument for node version (defaults to 'lts' if not provided)
|
||||
ARG NODE_VERSION=lts
|
||||
|
||||
# Stage 1: Build Vite React App
|
||||
FROM node:${NODE_VERSION}-alpine AS development
|
||||
|
||||
# Set the Node.js environment to development
|
||||
ENV NODE_ENV=development
|
||||
|
||||
# Set working directory for frontend code
|
||||
WORKDIR /frontend
|
||||
|
||||
# Copy package.json and package-lock.json for npm install
|
||||
COPY package*.json ./
|
||||
|
||||
# Install the latest npm version
|
||||
RUN npm install -g npm
|
||||
|
||||
# Install dependencies (this includes Vite and its plugins)
|
||||
RUN npm install --legacy-peer-deps
|
||||
|
||||
# Copy the rest of the application code
|
||||
COPY . .
|
||||
|
||||
# Run the build command (build the Vite app)
|
||||
RUN npm run build
|
||||
|
||||
# Stage 2: Serve with Nginx
|
||||
FROM nginx:alpine
|
||||
|
||||
# Copy the built Vite files from the build stage into Nginx's default HTML folder
|
||||
COPY --from=development /frontend/dist /usr/share/nginx/html
|
||||
|
||||
# Optionally copy a custom Nginx config (if needed)
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
# Expose port 80 for Nginx (default HTTP port)
|
||||
EXPOSE 80
|
||||
|
||||
# Start Nginx in the foreground (this is required to keep the container running)
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
15
app/nginx.conf
Normal file
15
app/nginx.conf
Normal file
@@ -0,0 +1,15 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
# Point to the Vite build output directory
|
||||
root /usr/share/nginx/html/dist;
|
||||
index index.html;
|
||||
|
||||
location / {
|
||||
try_files $uri /index.html;
|
||||
}
|
||||
|
||||
# Redirect 404 errors to index.html (for React Router)
|
||||
error_page 404 /index.html;
|
||||
}
|
||||
Reference in New Issue
Block a user