Skip to content

Commit e9fffe9

Browse files
committed
launched webapp with docker over aws ec2 instance
1 parent a1549df commit e9fffe9

1 file changed

Lines changed: 117 additions & 0 deletions

File tree

  • Launch webapp with Docker over Ec2 instance
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Hosting and Launching a Web Application with Docker on AWS EC2 Instance 🚀
2+
3+
## Overview
4+
5+
This guide provides a step-by-step process to host and launch a web application using Docker on an AWS EC2 instance.
6+
7+
## Prerequisites 📋
8+
9+
- An AWS account
10+
- Basic knowledge of AWS and Docker
11+
- AWS CLI installed and configured
12+
- SSH access to your EC2 instance
13+
14+
## Step-by-Step Guide 🛠️
15+
16+
### Step 1: Launch an EC2 Instance 🚀
17+
18+
1. **Log in to the AWS Management Console**:
19+
![AWS Management Console](https://d1.awsstatic.com/Developer%20Marketing/Cloud%20Computing.4e208de808476c71af24b19e7e152eed.png)
20+
21+
2. **Navigate to the EC2 Dashboard** and click "Launch Instance":
22+
![EC2 Dashboard](https://d2908q01vomqb2.cloudfront.net/6562cd234fbd38b69ab20c3650da0b0d3088bc2b/2021/04/22/1.png)
23+
24+
3. **Choose an Amazon Machine Image (AMI)**: Select the latest Ubuntu AMI.
25+
![Choose AMI](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/launch_instance_ubuntu.png)
26+
27+
4. **Choose an Instance Type**: Select t2.micro (eligible for the free tier).
28+
![Choose Instance Type](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/launch_instance_instance_type.png)
29+
30+
5. **Configure Instance Details**: Keep the default settings.
31+
![Configure Instance Details](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/launch_instance_configure_instance.png)
32+
33+
6. **Add Storage**: Keep the default settings.
34+
![Add Storage](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/launch_instance_add_storage.png)
35+
36+
7. **Add Tags**: Add a tag with Key = `Name` and Value = `Docker-WebApp`.
37+
![Add Tags](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/launch_instance_add_tags.png)
38+
39+
8. **Configure Security Group**:
40+
- Create a new security group.
41+
- Add rules to allow SSH (port 22) and HTTP (port 80).
42+
![Configure Security Group](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/launch_instance_configure_security_group.png)
43+
44+
9. **Review and Launch**: Click "Launch" and create a new key pair or use an existing one. Download the key pair.
45+
![Review and Launch](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/launch_instance_review.png)
46+
47+
### Step 2: Connect to Your EC2 Instance 🔗
48+
49+
1. **Open your terminal** and navigate to the directory containing your key pair file.
50+
51+
2. **Change the permissions of the key pair file**:
52+
53+
```sh
54+
chmod 400 your-key-pair.pem
55+
56+
3. **Connect to your instance:**
57+
```sh
58+
ssh -i "your-key-pair.pem" ubuntu@your-ec2-public-dns
59+
60+
### Step 3: Install Docker on EC2 Instance 🐳
61+
62+
1. **Update the package database:**
63+
```sh
64+
sudo apt-get update
65+
66+
2. **Install Docker:**
67+
```sh
68+
sudo apt-get install -y docker.io
69+
70+
3. **Start Docker and enable it to start on boot:**
71+
```sh
72+
sudo systemctl start docker
73+
sudo systemctl enable docker
74+
75+
4. **Verify Docker installation:"
76+
```sh
77+
docker --version
78+
79+
### Step 4: Set Up Your Web Application 📦
80+
1. **Clone your web application repository (replace the URL with your repository):**
81+
```sh
82+
git clone https://github.com/your-username/your-webapp.git
83+
cd your-webapp
84+
85+
2. **Create a Dockerfile in the root of your project (if not already present):**
86+
```dockerfile
87+
FROM node:14
88+
89+
WORKDIR /app
90+
91+
COPY package*.json ./
92+
93+
RUN npm install
94+
95+
COPY . .
96+
97+
EXPOSE 3000
98+
99+
CMD ["npm", "start"]
100+
```
101+
3. **Build the Docker image:**
102+
```sh
103+
docker build -t your-webapp .
104+
105+
4. **Run the Docker container:**
106+
```sh
107+
docker run -d -p 80:3000 your-webapp
108+
109+
### Step 5: Access Your Web Application 🌐
110+
Open a web browser and navigate to your EC2 instance's public DNS (IPv4) address.
111+
Your web application should be running and accessible on port 80.
112+
113+
### Conclusion 🎉
114+
You have successfully hosted and launched your web application using Docker on an AWS EC2 instance. Your application is now live and accessible via the internet.
115+
116+
117+

0 commit comments

Comments
 (0)