An open API service indexing awesome lists of open source software.

https://github.com/charlesmcmaponya/docker-ecs-react-app

A production ready React app containerized with Docker, pushed to AWS ECR, and prepared for deployment to ECS (Fargate). Includes local Docker testing and structured for future Terraform IaC integration.
https://github.com/charlesmcmaponya/docker-ecs-react-app

aws aws-ecr aws-ecs cloud containerization-with-docker deployment devops docker frontend iac reactjs terraform

Last synced: 3 days ago
JSON representation

A production ready React app containerized with Docker, pushed to AWS ECR, and prepared for deployment to ECS (Fargate). Includes local Docker testing and structured for future Terraform IaC integration.

Awesome Lists containing this project

README

          

# ๐Ÿณ Dockerized React App with ECS Deployment

This project demonstrates how to containerize a **React** application using **Docker**, test it locally, and prepare for deployment to **AWS ECS Fargate** using **Terraform**.

---

## ๐Ÿ“‚ Project Structure

```
docker-ecs-react-app/
โ”œโ”€โ”€ app/ # React app (built using Create React App)
โ”‚ โ”œโ”€โ”€ Dockerfile
โ”‚ โ”œโ”€โ”€ package.json
โ”‚ โ”œโ”€โ”€ public/
โ”‚ โ”œโ”€โ”€ src/
โ”‚ โ””โ”€โ”€ ...
โ”œโ”€โ”€ terraform/ # (Coming Soon) Terraform configs for AWS ECS + ECR
โ”œโ”€โ”€ screenshots/ # Project screenshots
โ””โ”€โ”€ README.md # This file
```

---

## ๐Ÿงฑ Built With

- โš›๏ธ React (via Create React App)
- ๐Ÿณ Docker
- โ˜๏ธ AWS ECR (Elastic Container Registry)
- ๐Ÿš€ AWS ECS (Elastic Container Service, Fargate)
- ๐Ÿ“œ Terraform (Infrastructure as Code โ€” coming soon)

---

## ๐Ÿณ Docker Workflow

### ๐Ÿ”จ Build Docker Image

```bash
docker build -t react-docker-app .
```

### ๐Ÿƒ Run Container Locally
```bash
docker run -d -p 3000:80 --name react-docker-container react-docker-app
```
Visit: http://localhost:3000

---

## โ˜๏ธ Push to AWS ECR

### Step 1: Create Repository
```bash
aws ecr create-repository --repository-name react-docker-app --region us-east-1
```

### Step 2: Authenticate Docker
```bash
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 188252831771.dkr.ecr.us-east-1.amazonaws.com
```

### Step 3: Tag Docker Image
```bash
docker tag react-docker-app:latest 188252831771.dkr.ecr.us-east-1.amazonaws.com/react-docker-app:latest
```

### Step 4: Push to ECR
```bash
docker push 188252831771.dkr.ecr.us-east-1.amazonaws.com/react-docker-app:latest
```

---

## ๐Ÿงน Git Repository Cleanup

### Problem: Large File in Git History
During development, a large screenshot file (`screenshots/docker-build-success.png.jpg`) was accidentally committed, causing issues with repository size and push operations.

### Solution: Using git-filter-repo
**Step 1:** Install git-filter-repo
```bash
pip install git-filter-repo
```

**Step 2:** Remove the large file from Git history
```bash
git filter-repo --path screenshots/docker-build-success.png.jpg --invert-paths --force
```

**Step 3:** Re-add remote and push cleaned repository
```bash
git remote add origin https://github.com/YOUR_USERNAME/YOUR_REPO.git
git push origin main --force
```

### โš ๏ธ Important Notes:
- This **permanently removes** the file from Git history
- Always backup your repository before running cleanup commands
- The `--force` flag is needed when working on your original repository
- `git-filter-repo` removes remotes for safety - you need to add them back

---

## ๐Ÿ“ธ Screenshots

All screenshots are saved in the `screenshots/` folder:

โœ… Container running successfully
โœ… ECR image successfully pushed
โœ… Project folder view

---

## ๐Ÿ‘ค Author

**Mosehla Charles Maponya**

---

## ๐Ÿ“„ License

MIT โ€“ Free to use and modify.