β
Next.js Frontend - Modern React app with API integration
β
Nginx Load Balancer - Routes traffic between frontend and backend
β
.NET 8.0 Backend - RESTful API with Swagger documentation
β
Docker Setup - Complete containerization with docker-compose
# 1. Navigate to the project directory
cd docker-setup
# 2. Build and start all services
docker-compose up --build
# 3. Open your browser
# Frontend: http://localhost:3000
# Swagger: http://localhost:80/swagger (via load balancer)That's it! π
Open http://localhost:3000 in your browser. You should see:
- Beautiful gradient "Hello World!" title
- Three cards showing the tech stack
- "Test Backend API" button
Click the "Test Backend API" button on the frontend. You should see:
{
"success": true,
"message": "Successfully connected to .NET backend!",
"backend": {
"message": "Hello from .NET Backend!",
"timestamp": "2024-02-20T10:30:00Z",
"version": "1.0.0",
"framework": ".NET 8.0"
},
"connectedAt": "2024-02-20T10:30:05Z"
}Via Load Balancer:
# Health check
curl http://localhost/api/health
# Hello endpoint
curl http://localhost/api/hello
# Time endpoint
curl http://localhost/api/time
# Echo endpoint
curl -X POST http://localhost/api/echo \
-H "Content-Type: application/json" \
-d '{"message":"Testing!"}'Direct to Backend (bypassing load balancer):
curl http://localhost:5000/api/helloOpen http://localhost/swagger in your browser to see interactive API documentation.
βββββββββββββββ
β Browser β
ββββββββ¬βββββββ
β
β
ββββββββββββββββββββββββββββββββ
β Next.js Frontend β
β http://localhost:3000 β
ββββββββββββ¬ββββββββββββββββββββ
β
β
ββββββββββββββββββββββββββββββββ
β Nginx Load Balancer β
β http://localhost:80 β
β - Routes to frontend β
β - Routes /api/* to backend β
ββββββββββββ¬ββββββββββββββββββββ
β
β
ββββββββββββββββββββββββββββββββ
β .NET Backend β
β Internal: backend:5000 β
β - REST API β
β - Swagger docs β
ββββββββββββββββββββββββββββββββ
# Check running containers
docker-compose ps
# You should see:
# nextjs-frontend running
# nginx-loadbalancer running
# dotnet-backend running
# View logs
docker-compose logs -f
# View specific service logs
docker-compose logs -f backend
docker-compose logs -f frontend
docker-compose logs -f nginx- Edit files in
frontend/app/ - Rebuild:
docker-compose up --build frontend - Or develop locally:
cd frontend && npm install && npm run dev
- Edit files in
backend/ - Rebuild:
docker-compose up --build backend - Or develop locally:
cd backend && dotnet run
- Edit
nginx/nginx.conf - Restart:
docker-compose restart nginx
| Method | Endpoint | Description |
|---|---|---|
| GET | http://localhost:3000 | Frontend UI |
| GET | http://localhost/api/health | Backend health |
| GET | http://localhost/api/hello | Hello message |
| GET | http://localhost/api/time | Current time |
| POST | http://localhost/api/echo | Echo message |
| GET | http://localhost/swagger | API docs |
# Add PostgreSQL to docker-compose.yml
services:
postgres:
image: postgres:16-alpine
environment:
POSTGRES_DB: myapp
POSTGRES_USER: user
POSTGRES_PASSWORD: password
ports:
- "5432:5432"- Install JWT packages in backend
- Create login/register endpoints
- Add auth context in frontend
- User management
- File uploads
- Real-time features with SignalR
- Caching with Redis
- Add SSL certificates to Nginx
- Use environment variables for secrets
- Set up CI/CD pipeline
- Add monitoring and logging
# Check if backend is running
docker-compose ps backend
# Check backend logs
docker-compose logs backend
# Restart backend
docker-compose restart backend# Change ports in docker-compose.yml
# For frontend: Change "3000:3000" to "3001:3000"
# For nginx: Change "80:80" to "8080:80"# Stop and remove everything
docker-compose down -v
# Rebuild and restart
docker-compose up --build# Check if it's listening on correct port
docker-compose exec backend netstat -tlnp
# Check environment variables
docker-compose exec backend env | grep ASPNETCOREYour setup is working if:
- β
All three containers show as "running" in
docker-compose ps - β Frontend loads at http://localhost:3000
- β "Test Backend API" button returns JSON with backend info
- β Swagger UI loads at http://localhost/swagger
- β All curl commands return valid JSON responses
Congratulations! π You have a fully functional full-stack application running in Docker!
Need help? Check the README files in each directory for detailed documentation.