π AWS Deployment Guide: EC2 + Docker + ECR + ECS (Fargate)
π§± PHASE 1 β Launch EC2 Instance (Setup Machine)
π― Purpose
EC2 is used as a build server to create and push Docker images to ECR.
πΉ Steps
-
Go to AWS Console β EC2 β Launch Instance
-
Configure:
-
AMI: Ubuntu 22.04
-
Instance Type: t2.micro
-
Key Pair: Select
.pem -
Security Group:
- SSH (22) β Your IP
- HTTP (80) β Anywhere (optional)
-
-
Launch Instance β
βοΈ PHASE 2 β EC2 Setup (Docker + AWS CLI)
πΉ Connect to EC2
ssh -i your-key.pem ubuntu@your-ec2-public-ip
πΉ Step 1: Update System
sudo apt update -y
sudo apt upgrade -y
πΉ Step 2: Install Docker
sudo apt install docker.io -y
πΉ Step 3: Enable Docker Access
sudo usermod -aG docker $USER
sudo reboot
π Reconnect after reboot
πΉ Step 4: Verify Docker
docker --version
πΉ Step 5: Install AWS CLI
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo apt install unzip -y
unzip awscliv2.zip
sudo ./aws/install
πΉ Step 6: Verify AWS CLI
aws --version
πΉ Step 7: Configure AWS Credentials
aws configure
π Get Credentials:
-
Go to AWS β IAM β Users
-
Security Credentials β Create:
- Access Key
- Secret Key
Enter:
AWS Access Key ID
AWS Secret Access Key
Region (e.g., us-east-1)
Output format (json)
π¦ PHASE 3 β Amazon ECR (Docker Image Registry)
πΉ Step 1: Create Repository
-
Go to ECR β Create Repository
-
Choose:
- Public / Private (as required)
-
Copy Repository URI
πΉ Step 2: View Push Commands
Click "View push commands" β AWS gives 4 commands
πΉ Step 3: Login to ECR (Run First Command)
Example:
aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <repo-uri>
πΉ Step 4: Go to Your Project Folder
cd your-project-folder
πΉ Step 5: Build Docker Image
docker build -t your-image-name .
πΉ Step 6: Tag Image
docker tag your-image-name:latest <repo-uri>:latest
πΉ Step 7: Push to ECR
docker push <repo-uri>:latest
β Image successfully pushed to ECR
βοΈ PHASE 4 β Amazon ECS (Fargate Deployment)
πΉ Step 1: Create Cluster
-
Go to ECS β Clusters β Create
-
Select:
- Fargate (Serverless)
- Enable Container Insights (optional)
πΉ Step 2: Create Task Definition
Configuration:
- Launch type: Fargate
- Task Role: Default
πΉ Container Configuration
-
Container name: your-app
-
Image URI: Paste ECR URI
-
Port Mapping:
- Container port: 80 (or your app port)
πΉ Resource Allocation
- CPU: 256
- Memory: 512 MB
Click Create Task Definition β
πΉ Step 3: Run Task (Deploy)
- Go to Task Definitions β Select β Deploy / Run Task
πΉ Environment Configuration
- Launch type: Fargate
- Cluster: Select your cluster
- Number of tasks: 1
πΉ Networking
-
VPC: Your VPC
-
Subnet: Public subnet
-
Auto-assign Public IP: ENABLED
-
Security Group:
- Allow HTTP (80)
Click Run Task β
π PHASE 5 β Access Your Application
πΉ Steps
-
Go to ECS β Tasks
-
Click your running task
-
Find:
- Public IP
πΉ Open in Browser
http://<public-ip>
π Your app is live!
π§ Architecture Overview
Developer β EC2 (Docker Build)
β
Push Image
β
ECR
β
ECS (Fargate)
β
Running Container
β
Public IP
β Final Checklist
| Step | Status |
|---|---|
| EC2 Running | β |
| Docker Installed | β |
| AWS CLI Configured | β |
| Image Built | β |
| Image Pushed to ECR | β |
| ECS Cluster Created | β |
| Task Running | β |
| Public IP Accessible | β |
Result
- Docker image stored in ECR
- ECS pulls image automatically
- App runs without managing servers (Fargate)
- Accessible via public IP
Yaha dekhi chai class ma garya step by step RAW
π AWS EC2 β ECR β ECS (Fargate) Deployment Guide
π¦ PHASE 1 β EC2 Setup
Step 1: Create an EC2 Instance
Launch an Ubuntu EC2 instance from AWS Console.
Step 2: Update System Packages
sudo apt update -y
sudo apt upgrade -y
Step 3: Install Docker
sudo apt install docker.io -y
Step 4: Give Docker Access to EC2 User
sudo usermod -aG docker $USER
sudo reboot
Reconnect after reboot.
π¦ PHASE 2 β Amazon ECR Setup
Step 5: Go to Amazon ECR
Open Elastic Container Registry (ECR) in AWS Console.
Step 6: Choose Public Registry
Create or select a Public Repository.
Step 7: Align Architecture
Ensure image architecture matches your EC2 (e.g. x86_64).
Step 8: View Push Commands
Click View Push Commands.
π¦ PHASE 3 β Install AWS CLI on EC2
Step 9: Download AWS CLI
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
Step 10: Extract Installer
unzip awscliv2.zip
Step 11: Install AWS CLI
sudo ./aws/install
Step 12: Verify Installation
aws --version
Step 13: Configure AWS CLI
aws configure
Step 14: Create IAM Access Keys
Go to:
IAM β User β Security Credentials
Create:
- Access Key
- Secret Key
Use them in:
aws configure
π¦ PHASE 4 β Push Docker Image to ECR
Step 15: Run First ECR Push Command
Run login command provided by ECR.
Step 16: Go to GitHub Project Folder
cd your-project-folder
Step 17: Run Remaining Push Commands
Run:
- Build command
- Tag command
- Push command
Step 18: Verify Image is Pushed
Confirm Docker image appears in ECR.
π¦ PHASE 5 β ECS Setup
Step 19: Go to Amazon ECS
Open ECS in AWS Console.
Step 20: Create Cluster
Choose:
- Fargate
- Enable Container Insights
Step 21: Create Task Definition
Choose:
- Default Task Role
Step 22: Configure Container
- Copy ECR Image URI
- Paste into task definition
- Configure:
- Port Mapping
- Resource Allocation
Step 23: Deploy Task Definition
Deploy / Run Task.
Choose environment configuration.
Step 24: Get Public IP
Click running task β copy Public IP
Access:
http://<public-ip>
π Application deployed successfully.