**Deploy a Simple Dockerized Web App Using AWS Elastic Container Registry (ECR) & EC2!** In this tutorial, we will take a **Dockerized web application**, push it to **AWS ECR (Elastic Container Registry)**, and deploy it on an **AWS EC2 instance**. By the end of this video, you'll have a fully working web app running in the cloud!

---

## ** What You'll Learn in This Video:**
How to **Containerize a Web App with Docker**
How to **Push a Docker Image to AWS ECR**
How to **Launch an AWS EC2 Instance**
How to **Pull & Run a Docker Container on EC2**
How to **Expose the App to the Internet**

---

## ** Prerequisites:**
**AWS Account** ([Sign Up Here](https://aws.amazon.com/free/))
**Basic Knowledge of Docker & AWS CLI**
**Docker Installed Locally** ([Get Docker](https://www.docker.com/get-started))
**AWS CLI Installed & Configured** ([Install Guide](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html))

---

## ** Step 1: Create a Simple Web App**
Let’s create a simple **Flask app** (`app.py`):

```python
from flask import Flask

app = Flask(__name__)

@app.route("/")
def home():
return "Hello from Dockerized Flask App on AWS EC2!"

if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
```

Create a `requirements.txt` file:
```
flask
```

---

## ** Step 2: Create a Dockerfile**
Inside the project folder, create a file named **`Dockerfile`**:

```dockerfile
# Use an official Python runtime as a base image
FROM python:3.9

# Set the working directory
WORKDIR /app

# Copy project files into the container
COPY . /app/

# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Expose the application port
EXPOSE 5000

# Start the application
CMD ["python", "app.py"]
```

---

## ** Step 3: Build & Test Docker Image Locally**
Run the following commands in your project directory:

```bash
docker build -t my-web-app .
```
Test the app locally:

```bash
docker run -p 5000:5000 my-web-app
```
Open `http://localhost:5000` to verify the app is running.

---

## ** Step 4: Set Up AWS ECR & Push Docker Image**

### **1⃣ Create an AWS ECR Repository**
Run the following command to create a repository in AWS ECR:

```bash
aws ecr create-repository --repository-name my-web-app
```

### **2⃣ Authenticate Docker to AWS ECR**
```bash
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin aws_account_id.dkr.ecr.us-east-1.amazonaws.com
```

### **3⃣ Tag & Push Image to ECR**
```bash
docker tag my-web-app:latest aws_account_id.dkr.ecr.us-east-1.amazonaws.com/my-web-app:latest
docker push aws_account_id.dkr.ecr.us-east-1.amazonaws.com/my-web-app:latest
```
The image is now stored in AWS ECR!

---

## ** Step 5: Launch an AWS EC2 Instance**
1⃣ Go to **AWS EC2 Console**
2⃣ Click **Launch Instance**
3⃣ Choose **Ubuntu 22.04 LTS**
4⃣ Select **t2.micro (Free Tier Eligible)**
5⃣ Configure **Security Group**:
- Allow **SSH (port 22)**
- Allow **HTTP (port 80)**
- Allow **Custom TCP (port 5000)**
6⃣ Click **Launch** and **Download the Key Pair (`.pem` file)**

---

## ** Step 6: Connect to EC2 via SSH**

**For Mac/Linux Users:**
```bash
chmod 400 your-key.pem
ssh -i your-key.pem ubuntu@your-ec2-public-ip
```

**For Windows Users (Using PuTTY):**
1⃣ Convert `.pem` to `.ppk` using **PuTTYgen**
2⃣ Open **PuTTY**, enter **EC2 Public IP**, and load the `.ppk` key
3⃣ Click **Open** and log in as `ubuntu`

---

## ** Step 7: Install Docker on EC2**
Once logged in, install Docker on EC2:

```bash
sudo apt update && sudo apt upgrade -y
sudo apt install docker.io -y
sudo systemctl start docker
sudo systemctl enable docker
```

Verify Docker is installed:
```bash
docker --version
```

---

## ** Step 8: Pull & Run the Docker Image from AWS ECR**

### **1⃣ Authenticate Docker on EC2**
```bash
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin aws_account_id.dkr.ecr.us-east-1.amazonaws.com
```

### **2⃣ Pull the Docker Image**
```bash
docker pull aws_account_id.dkr.ecr.us-east-1.amazonaws.com/my-web-app:latest
```

### **3⃣ Run the Docker Container**
```bash
docker run -d -p 5000:5000 aws_account_id.dkr.ecr.us-east-1.amazonaws.com/my-web-app:latest
```

Your web app is now **running on port 5000** on AWS EC2!

---

## ** Step 9: Access the Web App on EC2**
To access your app, **open a web browser** and go to:

```
http://your-ec2-public-ip:5000
```

If the page loads with **"Hello from Dockerized Flask App on AWS EC2!"**, **your deployment was successful!**

---



### ** Hashtags:**
#AWS #ECR #EC2 #Docker #Flask #WebApp #CloudComputing #AWSDeployment #DevOps #DockerTutorial