From e4617a94386502c30445a1dab9b128dd4bf946d8 Mon Sep 17 00:00:00 2001 From: Rishi Mondal Date: Wed, 1 Jan 2025 17:48:10 +0000 Subject: [PATCH] Dockerize Container --- Dockerfile | 32 ++++++++++++++++++++++++++++++++ nginx.conf | 15 +++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 Dockerfile create mode 100644 nginx.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2219e6b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +# Stage 1: Build the React application +FROM node:18 AS builder + +# Set working directory inside the container +WORKDIR /app + +# Copy package.json and package-lock.json +COPY package.json ./ + +# Install dependencies +RUN npm install + +# Copy all source code +COPY . . + +# Build the React app +RUN npm run build + +# Stage 2: Serve the application with Nginx +FROM nginx:stable-alpine + +# Copy the built files from the previous stage +COPY --from=builder /app/build /usr/share/nginx/html + +# Copy the Nginx configuration +COPY nginx.conf /etc/nginx/conf.d/default.conf + +# Expose the port +EXPOSE 80 + +# Start the Nginx server +CMD ["nginx", "-g", "daemon off;"] diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..185d0f2 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,15 @@ +server { + listen 80; + + server_name localhost; + + root /usr/share/nginx/html; + + index index.html; + + location / { + try_files $uri /index.html; + } + + error_page 404 /index.html; +}