|
| 1 | +# Docker Deployment Guide |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This application uses Docker Compose to orchestrate three services: |
| 6 | +- **Database**: PostgreSQL 18 |
| 7 | +- **Backend**: .NET 9 GraphQL API |
| 8 | +- **Frontend**: Angular application served via Nginx |
| 9 | + |
| 10 | +All services are connected via a custom bridge network called `banktracking-network`. |
| 11 | + |
| 12 | +## Quick Start |
| 13 | + |
| 14 | +1. **Copy the environment file**: |
| 15 | + ```bash |
| 16 | + cp .env.example .env |
| 17 | + ``` |
| 18 | + |
| 19 | +2. **Update the JWT secret** in `.env`: |
| 20 | + ``` |
| 21 | + JWT_SECRET=your_secure_random_string_here |
| 22 | + ``` |
| 23 | + |
| 24 | +3. **Build and start all services**: |
| 25 | + ```bash |
| 26 | + docker compose up -d --build |
| 27 | + ``` |
| 28 | + |
| 29 | +4. **Access the application**: |
| 30 | + - Frontend: http://localhost |
| 31 | + - Backend API: http://localhost:5095/graphql |
| 32 | + - Database: localhost:5432 |
| 33 | + |
| 34 | +## Configuration Files |
| 35 | + |
| 36 | +### Backend |
| 37 | +- `appsettings.json` - Base configuration |
| 38 | +- `appsettings.Development.json` - Local development (localhost database) |
| 39 | +- `appsettings.Docker.json` - Container environment (uses service names) |
| 40 | + |
| 41 | +The backend automatically uses `appsettings.Docker.json` when running in containers because `ASPNETCORE_ENVIRONMENT=Docker`. |
| 42 | + |
| 43 | +### Frontend |
| 44 | +- `environment.development.ts` - Local development |
| 45 | +- `environment.production.ts` - Production build (proxies GraphQL through Nginx) |
| 46 | + |
| 47 | +The frontend production build uses `/graphql` which is proxied to the backend service via Nginx. |
| 48 | + |
| 49 | +## Network Architecture |
| 50 | + |
| 51 | +``` |
| 52 | +┌─────────────────────────────────────────────────────┐ |
| 53 | +│ banktracking-network (bridge) │ |
| 54 | +│ │ |
| 55 | +│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ |
| 56 | +│ │ database │◄─────┤ backend │◄─────┤ frontend │ │ |
| 57 | +│ │ :5432 │ │ :5095 │ │ :80 │ │ |
| 58 | +│ └────┬─────┘ └────┬─────┘ └────┬─────┘ │ |
| 59 | +│ │ │ │ │ |
| 60 | +└───────┼─────────────────┼──────────────────┼───────┘ |
| 61 | + │ │ │ |
| 62 | + Host:5432 Host:5095 Host:80 |
| 63 | +``` |
| 64 | + |
| 65 | +## Service Management |
| 66 | + |
| 67 | +### Start services |
| 68 | +```bash |
| 69 | +docker compose up -d |
| 70 | +``` |
| 71 | + |
| 72 | +### Stop services |
| 73 | +```bash |
| 74 | +docker compose down |
| 75 | +``` |
| 76 | + |
| 77 | +### View logs |
| 78 | +```bash |
| 79 | +# All services |
| 80 | +docker compose logs -f |
| 81 | + |
| 82 | +# Specific service |
| 83 | +docker compose logs -f backend |
| 84 | +docker compose logs -f frontend |
| 85 | +docker compose logs -f database |
| 86 | +``` |
| 87 | + |
| 88 | +### Rebuild after code changes |
| 89 | +```bash |
| 90 | +docker compose up -d --build |
| 91 | +``` |
| 92 | + |
| 93 | +### Clean everything (including volumes) |
| 94 | +```bash |
| 95 | +docker compose down -v |
| 96 | +``` |
| 97 | + |
| 98 | +## Health Checks |
| 99 | + |
| 100 | +All services include health checks: |
| 101 | +- **Database**: `pg_isready` check every 10s |
| 102 | +- **Backend**: GraphQL schema endpoint check every 30s |
| 103 | +- **Frontend**: HTTP check every 30s |
| 104 | + |
| 105 | +Services wait for their dependencies to be healthy before starting. |
| 106 | + |
| 107 | +## Environment Variables |
| 108 | + |
| 109 | +You can override configuration via environment variables: |
| 110 | + |
| 111 | +```bash |
| 112 | +# In .env file or export |
| 113 | +JWT_SECRET=your_production_secret |
| 114 | +POSTGRES_PASSWORD=your_secure_password |
| 115 | +``` |
| 116 | + |
| 117 | +The backend accepts these environment overrides: |
| 118 | +- `ConnectionStrings__DefaultConnection` |
| 119 | +- `Jwt__Secret` |
| 120 | +- `Jwt__Issuer` |
| 121 | +- `Jwt__Audience` |
| 122 | +- `Jwt__ExpiryMinutes` |
| 123 | + |
| 124 | +## Production Deployment |
| 125 | + |
| 126 | +For production: |
| 127 | + |
| 128 | +1. **Update secrets**: Change all default passwords and JWT secret |
| 129 | +2. **Use secrets management**: Consider Docker secrets or external secret management |
| 130 | +3. **Enable HTTPS**: Add SSL certificates and update Nginx config |
| 131 | +4. **Remove port mappings**: Only expose frontend (port 80/443) |
| 132 | +5. **Set resource limits**: Add memory and CPU limits to services |
| 133 | +6. **Use external database**: Point to a managed PostgreSQL instance |
| 134 | +7. **Enable monitoring**: Add logging and monitoring solutions |
| 135 | + |
| 136 | +## Troubleshooting |
| 137 | + |
| 138 | +### Backend can't connect to database |
| 139 | +- Check database health: `docker compose ps` |
| 140 | +- Verify network: `docker network inspect banktracking-network` |
| 141 | +- Check connection string in backend logs |
| 142 | + |
| 143 | +### Frontend can't reach backend |
| 144 | +- Check backend health: `curl http://localhost:5095/graphql?sdl` |
| 145 | +- Verify Nginx proxy config in `frontend/nginx.conf` |
| 146 | +- Check browser console for CORS errors |
| 147 | + |
| 148 | +### Port already in use |
| 149 | +- Change port mappings in `compose.yaml` |
| 150 | +- Or stop conflicting services |
0 commit comments