270 lines
5.0 KiB
Markdown
270 lines
5.0 KiB
Markdown
# 🐳 Container-Betrieb - Drohnenführer App
|
|
|
|
## Schnellstart mit Podman/Docker
|
|
|
|
### Voraussetzungen
|
|
- Podman oder Docker installiert
|
|
- Podman Compose oder Docker Compose installiert
|
|
|
|
### 1. Umgebungsvariablen konfigurieren
|
|
|
|
Erstelle eine `.env`-Datei im Projektroot:
|
|
|
|
```bash
|
|
cp .env.example .env
|
|
```
|
|
|
|
**WICHTIG:** Ändere den `JWT_SECRET` in der `.env`-Datei!
|
|
|
|
```env
|
|
JWT_SECRET=dein-sehr-sicheres-geheimnis-mit-mindestens-32-zeichen
|
|
```
|
|
|
|
### 2. Container starten
|
|
|
|
Mit Podman:
|
|
```bash
|
|
podman-compose up -d
|
|
```
|
|
|
|
Mit Docker:
|
|
```bash
|
|
docker-compose up -d
|
|
```
|
|
|
|
### 3. Logs prüfen
|
|
|
|
```bash
|
|
# Alle Services
|
|
podman-compose logs -f
|
|
|
|
# Nur Backend
|
|
podman-compose logs -f backend
|
|
|
|
# Nur Frontend
|
|
podman-compose logs -f frontend
|
|
```
|
|
|
|
### 4. App öffnen
|
|
|
|
- **Frontend:** http://localhost:8080
|
|
- **Backend API:** http://localhost:5000
|
|
- **MongoDB:** localhost:27017
|
|
|
|
### 5. Admin-Zugang
|
|
|
|
- **Username:** `admin`
|
|
- **Password:** `password` (oder `admin123` wenn Seeding durchgeführt)
|
|
|
|
**⚠️ WICHTIG:** Ändere das Admin-Passwort nach dem ersten Login!
|
|
|
|
## Services
|
|
|
|
| Service | Container Name | Port | Beschreibung |
|
|
|---------|---------------|------|--------------|
|
|
| Frontend | drohnenfuehrer-frontend | 8080 | React App mit Nginx |
|
|
| Backend | drohnenfuehrer-backend | 5000 | Node.js Express API |
|
|
| MongoDB | drohnenfuehrer-mongo | 27017 | MongoDB Datenbank |
|
|
|
|
## Nützliche Befehle
|
|
|
|
### Container stoppen
|
|
```bash
|
|
podman-compose down
|
|
```
|
|
|
|
### Container neu bauen (nach Code-Änderungen)
|
|
```bash
|
|
podman-compose up -d --build
|
|
```
|
|
|
|
### Container und Daten löschen
|
|
```bash
|
|
podman-compose down -v
|
|
```
|
|
|
|
### In Container einsteigen
|
|
```bash
|
|
# Backend
|
|
podman exec -it drohnenfuehrer-backend sh
|
|
|
|
# MongoDB
|
|
podman exec -it drohnenfuehrer-mongo mongosh
|
|
```
|
|
|
|
### Datenbank seeden (manuell)
|
|
```bash
|
|
podman exec -it drohnenfuehrer-backend node seed.js
|
|
```
|
|
|
|
### Health Checks prüfen
|
|
```bash
|
|
# Backend
|
|
curl http://localhost:5000/health
|
|
|
|
# Frontend
|
|
curl http://localhost:8080/health
|
|
```
|
|
|
|
## Produktions-Deployment
|
|
|
|
### 1. Sicherheit
|
|
|
|
**Erforderliche Änderungen vor Production:**
|
|
|
|
1. **JWT Secret ändern** (in `.env`):
|
|
```bash
|
|
# Generiere ein sicheres Secret
|
|
openssl rand -base64 32
|
|
```
|
|
|
|
2. **Admin-Passwort ändern** nach erstem Login
|
|
|
|
3. **CORS Origin anpassen** (in `.env`):
|
|
```env
|
|
CORS_ORIGIN=https://yourdomain.com
|
|
```
|
|
|
|
4. **MongoDB absichern:**
|
|
- Authentifizierung aktivieren
|
|
- Backup-Strategie einrichten
|
|
- Nicht öffentlich exponieren
|
|
|
|
### 2. Frontend API-URL
|
|
|
|
Im Frontend wird die API-URL zur **Build-Zeit** gesetzt. Für Production:
|
|
|
|
1. Passe `podman-compose.yml` an:
|
|
```yaml
|
|
frontend:
|
|
build:
|
|
args:
|
|
- REACT_APP_API_URL=https://api.yourdomain.com
|
|
```
|
|
|
|
2. Rebuild erforderlich:
|
|
```bash
|
|
podman-compose up -d --build frontend
|
|
```
|
|
|
|
### 3. Reverse Proxy (empfohlen)
|
|
|
|
Für Production solltest du einen Reverse Proxy (z.B. Traefik, Nginx) vorschalten:
|
|
- HTTPS/TLS-Terminierung
|
|
- Rate Limiting
|
|
- DDoS-Schutz
|
|
|
|
### 4. Volumes sichern
|
|
|
|
```bash
|
|
# Liste Volumes
|
|
podman volume ls
|
|
|
|
# Backup erstellen
|
|
podman run --rm -v drohnenfuehrer_mongo-data:/data -v $(pwd):/backup alpine tar czf /backup/mongo-backup-$(date +%Y%m%d).tar.gz -C /data .
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
### Backend startet nicht
|
|
```bash
|
|
# Logs checken
|
|
podman-compose logs backend
|
|
|
|
# Häufige Probleme:
|
|
# - MongoDB nicht erreichbar → warte 30s nach Start
|
|
# - JWT_SECRET fehlt → .env prüfen
|
|
```
|
|
|
|
### Frontend zeigt API-Fehler
|
|
```bash
|
|
# Prüfe ob Backend läuft
|
|
curl http://localhost:5000/health
|
|
|
|
# Prüfe Browser-Konsole auf CORS-Fehler
|
|
# → CORS_ORIGIN in .env anpassen
|
|
```
|
|
|
|
### Datenbank leer
|
|
```bash
|
|
# Seed-Skript ausführen
|
|
podman exec -it drohnenfuehrer-backend node seed.js
|
|
```
|
|
|
|
### Port bereits belegt
|
|
```bash
|
|
# Andere Ports in podman-compose.yml verwenden:
|
|
# ports:
|
|
# - "8081:80" # statt 8080
|
|
```
|
|
|
|
## Performance-Optimierung
|
|
|
|
### Multi-Stage Builds
|
|
Beide Dockerfiles nutzen bereits Multi-Stage Builds für minimale Image-Größen.
|
|
|
|
### Image-Größen prüfen
|
|
```bash
|
|
podman images | grep drohnenfuehrer
|
|
```
|
|
|
|
Erwartete Größen:
|
|
- Backend: ~180 MB (Node Alpine)
|
|
- Frontend: ~45 MB (Nginx Alpine)
|
|
- MongoDB: ~750 MB
|
|
|
|
## Entwicklung mit Containern
|
|
|
|
### Hot Reload für Backend
|
|
```yaml
|
|
# In podman-compose.yml anpassen:
|
|
backend:
|
|
volumes:
|
|
- ./backend:/app
|
|
- /app/node_modules
|
|
command: npm run dev
|
|
```
|
|
|
|
### Frontend Development Mode
|
|
Für Entwicklung besser lokaler Dev-Server mit `npm start`, nicht Container.
|
|
|
|
## Monitoring
|
|
|
|
### Container-Status
|
|
```bash
|
|
podman-compose ps
|
|
```
|
|
|
|
### Ressourcen-Verbrauch
|
|
```bash
|
|
podman stats
|
|
```
|
|
|
|
### Health Check Status
|
|
```bash
|
|
# Alle Services
|
|
for svc in backend frontend mongo; do
|
|
echo "=== $svc ==="
|
|
podman inspect drohnenfuehrer-$svc | grep -A5 Health
|
|
done
|
|
```
|
|
|
|
## Migration von lokalem Setup
|
|
|
|
Wenn du von lokalem MongoDB zu Container wechselst:
|
|
|
|
```bash
|
|
# 1. Export aus lokalem MongoDB
|
|
mongodump --db drohnenfuehrer --out ./dump
|
|
|
|
# 2. Import in Container
|
|
podman exec -i drohnenfuehrer-mongo mongorestore --drop /dump
|
|
```
|
|
|
|
## Weitere Informationen
|
|
|
|
- [Hauptdokumentation](../README.md)
|
|
- [API Documentation](../docs/API.md)
|
|
- [Architektur](../docs/ARCHITECTURE.md)
|
|
- [Gap Analysis](../gap-analysis.md)
|