Docker mit traefik und portainer
This commit is contained in:
133
DOCKER_REGISTRY.md
Normal file
133
DOCKER_REGISTRY.md
Normal file
@@ -0,0 +1,133 @@
|
||||
# Docker Registry Deployment Guide
|
||||
|
||||
## Option 1: Private Docker Registry (Empfohlen für Produktion)
|
||||
|
||||
### 1. Images in Registry pushen
|
||||
|
||||
#### GitHub Container Registry (ghcr.io)
|
||||
```bash
|
||||
# Login bei GitHub Container Registry
|
||||
echo $GITHUB_TOKEN | docker login ghcr.io -u YOUR_USERNAME --password-stdin
|
||||
|
||||
# Images taggen und pushen
|
||||
docker build -t ghcr.io/YOUR_USERNAME/rezepte-klaus-backend:latest ./nodejs-version/backend
|
||||
docker build -t ghcr.io/YOUR_USERNAME/rezepte-klaus-frontend:latest ./nodejs-version/frontend
|
||||
|
||||
docker push ghcr.io/YOUR_USERNAME/rezepte-klaus-backend:latest
|
||||
docker push ghcr.io/YOUR_USERNAME/rezepte-klaus-frontend:latest
|
||||
```
|
||||
|
||||
#### Docker Hub
|
||||
```bash
|
||||
# Login bei Docker Hub
|
||||
docker login
|
||||
|
||||
# Images taggen und pushen
|
||||
docker build -t YOUR_USERNAME/rezepte-klaus-backend:latest ./nodejs-version/backend
|
||||
docker build -t YOUR_USERNAME/rezepte-klaus-frontend:latest ./nodejs-version/frontend
|
||||
|
||||
docker push YOUR_USERNAME/rezepte-klaus-backend:latest
|
||||
docker push YOUR_USERNAME/rezepte-klaus-frontend:latest
|
||||
```
|
||||
|
||||
#### Private Registry (AWS ECR, Azure ACR, etc.)
|
||||
```bash
|
||||
# Beispiel für AWS ECR
|
||||
aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin YOUR_ACCOUNT.dkr.ecr.eu-central-1.amazonaws.com
|
||||
|
||||
# Images taggen und pushen
|
||||
docker build -t YOUR_ACCOUNT.dkr.ecr.eu-central-1.amazonaws.com/rezepte-klaus-backend:latest ./nodejs-version/backend
|
||||
docker build -t YOUR_ACCOUNT.dkr.ecr.eu-central-1.amazonaws.com/rezepte-klaus-frontend:latest ./nodejs-version/frontend
|
||||
|
||||
docker push YOUR_ACCOUNT.dkr.ecr.eu-central-1.amazonaws.com/rezepte-klaus-backend:latest
|
||||
docker push YOUR_ACCOUNT.dkr.ecr.eu-central-1.amazonaws.com/rezepte-klaus-frontend:latest
|
||||
```
|
||||
|
||||
### 2. Server-Deployment (nur Docker Compose)
|
||||
|
||||
Auf dem Server benötigen Sie nur diese Dateien:
|
||||
- `docker-compose.registry.yml`
|
||||
- `.env.production`
|
||||
- SQL-Dateien für die Datenbank-Initialisierung
|
||||
- `deploy-registry.sh`
|
||||
|
||||
```bash
|
||||
# Minimales Setup auf Server
|
||||
mkdir -p /opt/rezepte-klaus
|
||||
cd /opt/rezepte-klaus
|
||||
|
||||
# Nur diese Dateien kopieren:
|
||||
scp docker-compose.registry.yml user@server:/opt/rezepte-klaus/
|
||||
scp .env.production user@server:/opt/rezepte-klaus/
|
||||
scp *.sql user@server:/opt/rezepte-klaus/
|
||||
scp deploy-registry.sh user@server:/opt/rezepte-klaus/
|
||||
```
|
||||
|
||||
## Option 2: CI/CD Pipeline (Automatisiert)
|
||||
|
||||
### GitHub Actions Beispiel
|
||||
```yaml
|
||||
# .github/workflows/deploy.yml
|
||||
name: Build and Deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build and push backend
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: ./nodejs-version/backend
|
||||
push: true
|
||||
tags: ghcr.io/${{ github.repository }}/backend:${{ github.sha }},ghcr.io/${{ github.repository }}/backend:latest
|
||||
|
||||
- name: Build and push frontend
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: ./nodejs-version/frontend
|
||||
push: true
|
||||
tags: ghcr.io/${{ github.repository }}/frontend:${{ github.sha }},ghcr.io/${{ github.repository }}/frontend:latest
|
||||
|
||||
- name: Deploy to server
|
||||
uses: appleboy/ssh-action@v0.1.8
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
key: ${{ secrets.SSH_KEY }}
|
||||
script: |
|
||||
cd /opt/rezepte-klaus
|
||||
docker-compose -f docker-compose.registry.yml pull
|
||||
docker-compose -f docker-compose.registry.yml up -d
|
||||
```
|
||||
|
||||
## Vorteile der Registry-Lösung:
|
||||
|
||||
✅ **Kein Repository auf Server**: Nur Docker Compose und Config-Dateien
|
||||
✅ **Versionierung**: Tags für verschiedene Versionen (latest, v1.0.0, etc.)
|
||||
✅ **Sicherheit**: Keine Source-Code-Exposition auf Produktionsserver
|
||||
✅ **Geschwindigkeit**: Nur Image-Download, kein Build-Prozess
|
||||
✅ **Rollback**: Einfache Rückkehr zu vorherigen Versionen
|
||||
✅ **Multi-Server**: Gleiche Images auf mehreren Servern
|
||||
✅ **CI/CD Integration**: Automatische Builds und Deployments
|
||||
|
||||
## Deployment-Workflow:
|
||||
|
||||
1. **Entwicklung**: Code ändern, committen, pushen
|
||||
2. **CI/CD**: Automatischer Build und Push der Images
|
||||
3. **Server**: `docker-compose pull && docker-compose up -d`
|
||||
4. **Fertig**: Neue Version läuft
|
||||
|
||||
Das ist definitiv der professionellere Ansatz!
|
||||
Reference in New Issue
Block a user