A full-stack MERN (MongoDB, Express.js, React.js, Node.js) application with complete Docker containerization and CI/CD deployment to Azure Web App.
- Frontend: React 19.1.0 with Create React App
- Backend: Express.js 4.18.2 + Node.js 18
- Database: MongoDB Atlas (Cloud)
- Web Server: Nginx (for serving React app)
- Containerization: Docker + Docker Compose
- CI/CD: GitHub Actions
- Cloud Platform: Azure Web App with Container Registry (ACR)
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ React Client │────│ Nginx (Port 80) │────│ Azure Web App │
│ (Frontend) │ │ Reverse Proxy │ │ (Multi-cont.) │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│
▼
┌──────────────────┐ ┌─────────────────┐
│ Express Server │────│ MongoDB Atlas │
│ (Backend API) │ │ (Database) │
│ (Port 5000) │ └─────────────────┘
└──────────────────┘
mern-app/
├── client/ # React frontend
│ ├── src/
│ │ ├── App.js # Main React component with API integration
│ │ └── ...
│ ├── nginx.conf # Nginx configuration for reverse proxy
│ ├── Dockerfile # Multi-stage build (React + Nginx)
│ └── package.json
│
├── server/ # Express.js backend
│ ├── index.js # Main server file with MongoDB integration
│ ├── Dockerfile # Node.js container
│ ├── .env.example # Environment variables template
│ └── package.json
│
├── .github/workflows/
│ └── deploy.yml # CI/CD pipeline for Azure deployment
│
├── docker-compose.yml # Local development setup
├── docker-compose.prod.yml # Production deployment configuration
└── README.md
- ✅ Modern React 19 with Hooks
- ✅ User management interface (CRUD operations)
- ✅ Real-time API integration
- ✅ Environment-based API URL configuration
- ✅ Error handling and loading states
- ✅ Responsive design
- ✅ RESTful API endpoints
- ✅ MongoDB integration with Mongoose
- ✅ CORS configuration
- ✅ Health check endpoint
- ✅ Environment-based configuration
- ✅ Graceful shutdown handling
- ✅ Request logging and error handling
- ✅ Dockerized multi-container application
- ✅ Nginx reverse proxy for API routing
- ✅ Azure Container Registry (ACR) integration
- ✅ Automated CI/CD with GitHub Actions
- ✅ Environment variable management
- ✅ Container health checks
- ✅ Application logging and monitoring
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
API information and endpoints |
| GET | /api/health |
Health check and status |
| GET | /api/hello |
Simple test endpoint |
| GET | /api/users |
Get all users |
| POST | /api/users |
Create a new user |
- Docker & Docker Desktop
- Node.js 18+ (for local development)
- Azure account (for deployment)
- MongoDB Atlas account (for database)
-
Clone the repository
git clone <repository-url> cd mern-app
-
Set up environment variables
cp server/.env.example server/.env # Edit server/.env with your MongoDB connection string -
Run with Docker Compose
docker-compose up --build
-
Access the application
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000
- Health Check: http://localhost:5000/api/health
-
Backend setup
cd server npm install npm start -
Frontend setup
cd client npm install npm start
- Azure Web App for Containers
- Azure Container Registry (ACR)
- GitHub repository with required secrets
Add these secrets to your GitHub repository settings:
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/mernapp
AZURE_CREDENTIALS={"clientId":"...","clientSecret":"...","subscriptionId":"...","tenantId":"..."}
ACR_USERNAME=acr123
ACR_PASSWORD=your-acr-password- Push to main branch triggers GitHub Actions
- Docker images are built and pushed to ACR
- Azure Web App is configured with Docker Compose
- Environment variables are set
- Application is deployed and started
- Azure Portal: Monitor app performance and logs
- Health Check:
https://***.azurewebsites.net/api/health - Application Insights: Detailed telemetry and diagnostics
PORT=5000
NODE_ENV=production
MONGODB_URI=mongodb+srv://...
CORS_ORIGIN=https://***.azurewebsites.netWEBSITES_PORT=80
WEBSITES_ENABLE_APP_SERVICE_STORAGE=false
WEBSITES_CONTAINER_START_TIME_LIMIT=600
DOCKER_ENABLE_CI=true# Test Docker build
./test-docker.sh
# Test server health
curl http://localhost:5000/api/health
# Test API endpoints
curl http://localhost:5000/api/users# Health check
curl https://***.azurewebsites.net/api/health
# API test
curl https://***.azurewebsites.net/api/hello-
503 Service Unavailable
- Check container startup logs
- Verify environment variables
- Ensure MongoDB connection is valid
-
Container startup timeouts
- Check
WEBSITES_CONTAINER_START_TIME_LIMITsetting - Review application logs in Azure Portal
- Check
-
Database connection issues
- Verify MongoDB Atlas connection string
- Check network access settings in MongoDB Atlas
- Ensure IP whitelist includes Azure regions
# Check Azure Web App logs
az webapp log tail --name mern-app --resource-group mern-group
# Check container status
az webapp show --name mern-app --resource-group mern-group --query "state"
# Download logs
az webapp log download --name mern-app --resource-group mern-group- Container Health Checks: Automatic container restart on failure
- Nginx Caching: Static asset caching for improved performance
- Database Indexing: Optimized MongoDB queries
- CDN Ready: Static assets can be served via Azure CDN
- Horizontal Scaling: Ready for Azure App Service scaling
- Environment Variables: Secure credential management
- CORS Configuration: Controlled cross-origin requests
- Container Security: Non-root user execution
- HTTPS: SSL/TLS encryption via Azure
- Input Validation: API request validation
- ✅ Successfully deployed MERN stack to Azure
- ✅ Fixed path-to-regexp errors with Express.js
- ✅ Implemented multi-container Docker architecture
- ✅ Set up automated CI/CD pipeline
- ✅ Configured MongoDB Atlas integration
- ✅ Resolved HTTP 503 errors
- ✅ Optimized container startup and health checks
MIT License - feel free to use, modify, and distribute.