-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreactdeploy.txt
More file actions
89 lines (89 loc) · 2.31 KB
/
reactdeploy.txt
File metadata and controls
89 lines (89 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
9. Deploying a ReactJS application using Docker
�
� Deploy React App with AWS and Docker
This document outlines the complete process of deploying a
ReactJS application using Docker on an AWS EC2 instance. It
includes step-by-step instructions, terminal commands, and file
structures used.
�
� Project Directory Structure
reactdeploy/
├── Dockerfile
├── package.json
├── package-lock.json
├── public/
├── src/
├── .dockerignore
�
� Docker Configuration
Dockerfile
FROM node:18 AS build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN chmod +x node_modules/.bin/react-scripts
RUN npm run build
FROM nginx:alpine
COPY --from=build /app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
.dockerignore
node_modules
build
☁
️ Launch EC2 Instance on AWS
Go to AWS Console → EC2 → Launch Instance
Name: React Docker
OS: Amazon Linux 2
Instance Type: t2.micro (Free Tier)
Security Group:
o Allow SSH (port 22)
o Allow HTTP (port 80)
Download PEM key (e.g., reactdeployerpem.pem)
�
�
️ Terminal Operations
�
� Terminal 1: Connect to EC2
cd Downloads
ssh -i
"C:\Users\VENKATESH\Downloads\reactdeployerpem.pem"
ec2-user@ec2-35-173-178-7.compute-1.amazonaws.com
�
� Terminal 2: Upload React Project ZIP
Before uploading, compress your project folder reactdeploy to
reactdeploy.zip.
scp -i
"C:\Users\VENKATESH\Downloads\reactdeployerpem.pem"
"C:\Users\VENKATESH\OneDrive\Desktop\reactdeploy.zip" ec2
user@ec2-35-173-178-7.compute
1.amazonaws.com:/home/ec2-user/
�
� Back in Terminal 1
1. Install Docker
sudo yum update -y
sudo yum install -y docker
2. Start Docker
sudo systemctl start docker
sudo systemctl enable docker
3. Allow Docker without sudo (optional)
sudo usermod -aG docker ec2-user
exit
Then reconnect:
ssh -i
"C:\Users\VENKATESH\Downloads\reactdeployerpem.pem"
ec2-user@ec2-35-173-178-7.compute-1.amazonaws.com
4. Unzip and enter project folder
unzip reactdeploy.zip
cd reactdeploy
ls
You should see Dockerfile, .dockerignore, and other app files.
5. Build Docker Image
docker build -t kmit-react-app .
6. Run Docker Container
docker run -d -p 80:80 kmit-react-app
�
� Test in Browser
Open the following URL:
http://public ipv4 address of instance