diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..008412b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +# Stage 1: Build the app +FROM node:18-alpine AS builder + +WORKDIR /app + +# Copy only package files first for caching +COPY package*.json ./ + +# Install dependencies +RUN npm install + +# Copy the rest of the source code +COPY . . + +# Build the production static files +RUN npm run build + + +# Stage 2: Run the built app using a minimal Node image +FROM node:18-alpine AS runner + +# Install serve globally +RUN npm install -g serve + +# Create working directory +WORKDIR /app + +# Copy only the built static files from builder stage +COPY --from=builder /app/build ./build + +# Serve the static files +CMD ["serve", "-s", "build", "-l", "3000"] + +EXPOSE 3000 diff --git a/README.md b/README.md index b1fe6dd..3a3f3bc 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ See the live project in action: https://react-js-simple-calculator.netlify.app/ - HTML - CSS - JS - +- Docker ## Getting Started To get a local copy up and running, follow these steps: @@ -31,6 +31,22 @@ To get a local copy up and running, follow these steps: 3. Install dependencies: `npm install` 4. Start the development server: `npm start` +## You Can Run Project directly in using Docker(ubuntu os) + +1. Install Docker in ubuntu operating system + - update o.s i.e. sudo apt-get update --y + - install docker i.e. sudo apt-get install docker.io +2. Give permissions to access docker images and containers without sudo user + - sudo useradd -aG docker $USER + - sudo chmod 666 /var/run/docker.sock +3. Build the docker image using below command + - docker build -t calapp . +4. Run the docker container using below command + - docker run -itd -p 3000:3000 --name=calapp calapp +5. Check the containers are up or not + - docker ps +6. Access Your application on 3000 port. + ## Usage 1. Click the buttons to input numbers and operators.