197 lines
6.0 KiB
Markdown
197 lines
6.0 KiB
Markdown
# Docker Compose Clients Fix - Problemlösung
|
|
|
|
## 🎯 Problemstellung
|
|
|
|
**Ursprünglicher Fehler:**
|
|
```bash
|
|
/usr/bin/docker compose -f /home/stefan/WsMeldestelle/Meldestelle/docker-compose.clients.yml -p meldestelle up -d
|
|
service "desktop-app" depends on undefined service "api-gateway": invalid compose project
|
|
`docker-compose` process finished with exit code 1
|
|
```
|
|
|
|
## 🔍 Problemanalyse
|
|
|
|
### **Hauptproblem:** Fehlende Service-Dependencies
|
|
- **web-app** und **desktop-app** Services hatten `depends_on: - api-gateway`
|
|
- **api-gateway** Service ist aber in `docker-compose.yml` definiert, nicht in `docker-compose.clients.yml`
|
|
- Bei standalone Ausführung von `docker-compose.clients.yml` konnte Docker den `api-gateway` Service nicht finden
|
|
|
|
### **Betroffene Services:**
|
|
1. **web-app**: `depends_on: - api-gateway` (Zeile 27-28)
|
|
2. **desktop-app**: `depends_on: - api-gateway` (Zeile 64-65)
|
|
|
|
## ✅ Implementierte Lösung
|
|
|
|
### **1. Dependencies entfernt**
|
|
```yaml
|
|
# VORHER (problematisch):
|
|
web-app:
|
|
# ...
|
|
depends_on:
|
|
- api-gateway
|
|
|
|
desktop-app:
|
|
# ...
|
|
depends_on:
|
|
- api-gateway
|
|
```
|
|
|
|
```yaml
|
|
# NACHHER (funktioniert):
|
|
web-app:
|
|
# ...
|
|
# depends_on removed for standalone client deployment
|
|
# When using multi-file setup, api-gateway dependency is handled externally
|
|
|
|
desktop-app:
|
|
# ...
|
|
# depends_on removed for standalone client deployment
|
|
# When using multi-file setup, api-gateway dependency is handled externally
|
|
```
|
|
|
|
### **2. Flexible API-Gateway Konfiguration**
|
|
```yaml
|
|
# VORHER (hardcodiert):
|
|
environment:
|
|
API_BASE_URL: http://api-gateway:${GATEWAY_PORT:-8081}
|
|
|
|
# NACHHER (flexibel):
|
|
environment:
|
|
API_BASE_URL: http://${GATEWAY_HOST:-api-gateway}:${GATEWAY_PORT:-8081}
|
|
```
|
|
|
|
**Vorteile:**
|
|
- **Standalone**: `GATEWAY_HOST=localhost` für externe Gateway-Verbindung
|
|
- **Multi-File**: `GATEWAY_HOST` nicht gesetzt = verwendet `api-gateway` (Container-Name)
|
|
|
|
### **3. Erweiterte Usage-Dokumentation**
|
|
Klare Deployment-Szenarien hinzugefügt:
|
|
1. **Standalone Client Deployment** (jetzt möglich)
|
|
2. **Multi-File mit Infrastruktur**
|
|
3. **Komplettes System**
|
|
|
|
## 🚀 Usage-Beispiele
|
|
|
|
### **1. Standalone Client Deployment (FIXED)**
|
|
```bash
|
|
# Clients alleine starten (externe API-Gateway Verbindung)
|
|
GATEWAY_HOST=localhost docker compose -f docker-compose.clients.yml up -d
|
|
|
|
# Oder mit .env Datei:
|
|
echo "GATEWAY_HOST=localhost" >> .env
|
|
docker compose -f docker-compose.clients.yml up -d
|
|
```
|
|
|
|
**Verwendungszweck:**
|
|
- Development: Client-Development gegen lokalen Gateway
|
|
- Staging: Clients gegen remote Gateway-Instance
|
|
- Testing: Isoliertes Client-Testing
|
|
|
|
### **2. Multi-File mit Infrastruktur**
|
|
```bash
|
|
# Infrastructure + Clients
|
|
docker compose -f docker-compose.yml -f docker-compose.clients.yml up -d
|
|
```
|
|
|
|
**Service-Start-Reihenfolge:**
|
|
1. Infrastructure Services (postgres, redis, consul, api-gateway)
|
|
2. Client Services (web-app, desktop-app)
|
|
|
|
### **3. Vollständiges System**
|
|
```bash
|
|
# Infrastructure + Backend Services + Frontend Clients
|
|
docker compose -f docker-compose.yml -f docker-compose.services.yml -f docker-compose.clients.yml up -d
|
|
```
|
|
|
|
## 📋 Validierung und Tests
|
|
|
|
### **Standalone Deployment Test:**
|
|
```bash
|
|
✅ docker compose -f docker-compose.clients.yml config --quiet
|
|
# Kein Fehler - Problem behoben!
|
|
```
|
|
|
|
### **Multi-File Setup Test:**
|
|
```bash
|
|
✅ docker compose -f docker-compose.yml -f docker-compose.clients.yml config --quiet
|
|
# Funktioniert einwandfrei
|
|
```
|
|
|
|
### **Vollständiges System Test:**
|
|
```bash
|
|
✅ docker compose -f docker-compose.yml -f docker-compose.services.yml -f docker-compose.clients.yml config --quiet
|
|
# Alle Konfigurationen gültig
|
|
```
|
|
|
|
## 🔧 Environment-Variablen
|
|
|
|
### **Neue Variables für Client-Konfiguration:**
|
|
```bash
|
|
# Gateway-Host (für standalone deployment)
|
|
GATEWAY_HOST=localhost # Externe Gateway-Verbindung
|
|
GATEWAY_HOST=api-gateway # Container-zu-Container (default)
|
|
|
|
# Gateway-Port
|
|
GATEWAY_PORT=8081 # Standard API Gateway Port
|
|
|
|
# App-Konfiguration
|
|
APP_NAME=Meldestelle
|
|
APP_VERSION=1.0.0
|
|
NODE_ENV=production
|
|
```
|
|
|
|
## 🎯 Problemlösung im Detail
|
|
|
|
### **Root Cause:**
|
|
- Docker Compose kann Services nur innerhalb desselben Compose-File oder -Projekts referenzieren
|
|
- `depends_on` funktioniert nicht file-übergreifend bei standalone Ausführung
|
|
- Client-Services müssen unabhängig startbar sein
|
|
|
|
### **Solution Pattern:**
|
|
1. **Dependency Removal**: Entfernung harter Dependencies zu externen Services
|
|
2. **Flexible Configuration**: Environment-Variable für externe Service-Verbindungen
|
|
3. **Multi-Mode Support**: Unterstützung sowohl standalone als auch multi-file deployment
|
|
4. **Clear Documentation**: Eindeutige Usage-Szenarien und Beispiele
|
|
|
|
## 🌟 Vorteile der Lösung
|
|
|
|
### **✅ Standalone Deployment:**
|
|
- Clients können unabhängig von der Infrastruktur gestartet werden
|
|
- Flexibel konfigurierbare Gateway-Verbindungen
|
|
- Ideal für Development und Testing
|
|
|
|
### **✅ Multi-File Deployment:**
|
|
- Funktioniert weiterhin einwandfrei
|
|
- Automatische Container-zu-Container Kommunikation
|
|
- Optimale Production-Deployment
|
|
|
|
### **✅ Maintenance:**
|
|
- Klare Deployment-Szenarien dokumentiert
|
|
- Flexible Environment-Variable Konfiguration
|
|
- Keine Breaking Changes für existierende Deployments
|
|
|
|
## 📝 Deployment-Checkliste
|
|
|
|
### **Für Standalone Client Deployment:**
|
|
- [ ] `GATEWAY_HOST` Environment-Variable setzen
|
|
- [ ] Externe API Gateway ist erreichbar
|
|
- [ ] Ports 4000 (web-app) und 6080 (desktop-app) sind verfügbar
|
|
|
|
### **Für Multi-File Deployment:**
|
|
- [ ] Infrastruktur-Services starten zuerst
|
|
- [ ] Netzwerk `meldestelle-network` ist verfügbar
|
|
- [ ] API Gateway ist healthy bevor Clients starten
|
|
|
|
### **Für Production Deployment:**
|
|
- [ ] Alle Environment-Variablen in `.env` konfiguriert
|
|
- [ ] Health-Checks funktionieren
|
|
- [ ] Nginx Reverse-Proxy korrekt konfiguriert
|
|
|
|
## ✅ Status: Problem gelöst
|
|
|
|
**Original Error:** `service "desktop-app" depends on undefined service "api-gateway": invalid compose project`
|
|
|
|
**Status:** ✅ **BEHOBEN**
|
|
|
|
Die `docker-compose.clients.yml` kann nun erfolgreich standalone ausgeführt werden und funktioniert gleichzeitig einwandfrei im Multi-File-Setup.
|