Create individual Dockerfiles for both frontend and backend applications to package all dependencies and application code into containers.
Build a docker-compose.yml file that orchestrates all services (MongoDB, Backend, Frontend) to work together seamlessly.
Run docker-compose up -d to verify everything works locally before deployment.
Instance Configuration:
- Make sure the instance has a minimum required hardware and has an public IP and associated with a configured sercurity group.
Use SSH to connect to your EC2 instance with your private key.
Install the following on your EC2 instance:
- Docker: Container runtime
- Docker Compose: Multi-container orchestration
- Git: Version control system
- Nginx: Web server and reverse proxy
Clone your project repository from GitHub to the EC2 instance.
Execute docker-compose up -d to start all services in detached mode.
Set up Nginx as a reverse proxy
- The configuration steps are present in ./nginx-congig/README.md
Create a workflow file that automatically:
- Triggers on push to main branch
- Builds Docker images for frontend and backend
- Pushes images to Docker Hub registry
Set up secure credentials:
- Docker Hub username
- Docker Hub access token
┌─────────────┐ ┌──────────────┐ ┌─────────────┐ ┌──────────────┐
│ Code Push │──▶│ GitHub │──▶│ Build │──▶│ Push to │
│ to main │ │ Actions │ │ Docker │ │ Docker Hub │
│ branch │ │ Triggered │ │ Images │ │ Registry │
└─────────────┘ └──────────────┘ └─────────────┘ └──────────────┘
- Frontend: http://localhost:4200
- Backend API: http://localhost:3000
- Database: localhost:27017
- Via Nginx Proxy: http://your-ec2-public-ip