Files
OpenTournament/docker/README.md
2025-07-19 12:21:46 +02:00

165 lines
3.3 KiB
Markdown

# Tournament Application Docker Setup
This directory contains the Docker configuration for the Tournament Application.
## Files
- `Dockerfile` - Multi-stage build for the application
- `docker-compose.yml` - Complete stack with PostgreSQL and Nginx
- `nginx.conf` - Nginx reverse proxy configuration
- `.dockerignore` - Excludes unnecessary files from build context
## Quick Start
### Prerequisites
- Docker
- Docker Compose
### Running the Application
1. **Start the complete stack:**
```bash
cd docker
docker-compose up -d
```
2. **Access the application:**
- Frontend: http://localhost:80
- API: http://localhost:4000
- Database: localhost:5432
3. **View logs:**
```bash
docker-compose logs -f
```
4. **Stop the application:**
```bash
docker-compose down
```
## Services
### Tournament App (Port 4000)
- Node.js backend with Express
- React frontend (built and served by backend)
- Prisma ORM for database operations
- Socket.IO for real-time updates
### PostgreSQL (Port 5432)
- Database: `tournament`
- User: `tournament_user`
- Password: `tournament_password`
### Nginx (Port 80/443)
- Reverse proxy for the application
- Static file serving
- SSL termination (configured but disabled by default)
## Environment Variables
The application uses the following environment variables:
```env
DATABASE_URL=postgresql://tournament_user:tournament_password@postgres:5432/tournament
PORT=4000
JWT_SECRET=your-super-secret-jwt-key-change-in-production
ADMIN_USERNAME=admin
ADMIN_PASSWORD=admin123
ADMIN_EMAIL=admin@tournament.com
```
## Development
### Building the Image
```bash
cd docker
docker build -t tournament-app -f Dockerfile ..
```
### Running with Custom Environment
```bash
docker-compose -f docker-compose.yml -f docker-compose.override.yml up
```
## Production Deployment
### Security Considerations
1. **Change default passwords:**
- Update `ADMIN_PASSWORD` in docker-compose.yml
- Update `JWT_SECRET` to a strong random string
- Update PostgreSQL password
2. **Enable HTTPS:**
- Uncomment HTTPS section in nginx.conf
- Add SSL certificates to `./ssl/` directory
- Update domain name in nginx.conf
3. **Database Security:**
- Use external PostgreSQL instance in production
- Implement proper backup strategy
- Use connection pooling
### Scaling
The application can be scaled horizontally:
```bash
docker-compose up -d --scale tournament-app=3
```
## Troubleshooting
### Database Connection Issues
1. Check if PostgreSQL is running:
```bash
docker-compose ps postgres
```
2. Check database logs:
```bash
docker-compose logs postgres
```
### Application Issues
1. Check application logs:
```bash
docker-compose logs tournament-app
```
2. Access application shell:
```bash
docker-compose exec tournament-app sh
```
### Nginx Issues
1. Check nginx logs:
```bash
docker-compose logs nginx
```
2. Test nginx configuration:
```bash
docker-compose exec nginx nginx -t
```
## Data Persistence
The PostgreSQL data is persisted in a Docker volume named `postgres_data`. To backup:
```bash
docker-compose exec postgres pg_dump -U tournament_user tournament > backup.sql
```
To restore:
```bash
docker-compose exec -T postgres psql -U tournament_user tournament < backup.sql
```