I Have A Simple Web Project in React, Node Js And...
I Have A Simple Web Project in React, Node Js And...
Here's a detailed guide on uploading your project with client (React) and server (Node.js) sides,
along with running it on Docker:
Prerequisites:
Steps:
EXPOSE 3000 # Expose the port where your Node.js server listens
(usually 3000)
The -d flag runs the container in detached mode, and --name assigns it a name for
easier management.
○ Node.js Backend:
Bash
docker run -d --name backend -p 3000:3000 <your-image-name>
The -p flag maps the container's port (3000) to the host's port (3000), making your
application accessible.
○ React Frontend (optional): If you have a separate frontend image:
Bash
docker run -d --name frontend -p 80:80 <your-frontend-image-name>
This maps the container's port (80) to the host's port (80), allowing access to the
frontend.
5. Run the Containers (Option 2: Multi-stage Build):
○ This approach combines frontend and backend into a single image, reducing size.
However, it requires modifications to your Node.js server to serve the React app's static
content.
○ Modify your Node.js Dockerfile to include these steps after installing dependencies:
Dockerfile
COPY . .
RUN npm run build # Build the React app within the container