Warum eine eigene Docker Registry?
- Datenschutz: Images verlassen das Firmennetz nicht
- Performance: Schnelleres Pulling aus dem internen Netz
- Kosten: Kein Registry-Abo (GitHub Container Registry kostet ab ~4 $/Monat für private Images)
- Kontrolle: Eigene Retention-Policies und Zugriffsrechte
Docker Registry mit Docker Compose
services:
registry:
image: registry:2
container_name: registry
restart: unless-stopped
ports:
- "5000:5000"
volumes:
- registry-data:/var/lib/registry
- ./auth:/auth:ro
- ./config.yml:/etc/docker/registry/config.yml:ro
volumes:
registry-data:
Authentifizierung einrichten
# htpasswd-Datei erstellen
mkdir -p auth
docker run --rm --entrypoint htpasswd httpd:2 \
-Bbn admin IhrPasswort > auth/htpasswd
# Zweiten Benutzer hinzufügen
docker run --rm --entrypoint htpasswd httpd:2 \
-Bbn developer DevPasswort >> auth/htpasswd
Registry-Konfiguration
# config.yml
version: 0.1
log:
level: info
storage:
filesystem:
rootdirectory: /var/lib/registry
delete:
enabled: true
auth:
htpasswd:
realm: basic-realm
path: /auth/htpasswd
http:
addr: :5000
secret: einzufaelligesgeheimnis
health:
storagedriver:
enabled: true
interval: 10s
threshold: 3
Images pushen und pullen
# Anmelden
docker login registry.firma.de:5000
# Image taggen und pushen
docker tag nginx:alpine registry.firma.de:5000/nginx:alpine
docker push registry.firma.de:5000/nginx:alpine
# Image pullen
docker pull registry.firma.de:5000/nginx:alpine
# Alle Images in Registry auflisten (API)
curl -s -u admin:Passwort https://registry.firma.de:5000/v2/_catalog | jq
Garbage Collection (alte Images löschen)
# Garbage Collection manuell ausführen
docker exec registry bin/registry garbage-collect \
/etc/docker/registry/config.yml --delete-untagged
# Automatisch per Cron (nachts)
0 3 * * * docker exec registry bin/registry garbage-collect /etc/docker/registry/config.yml --delete-untagged
Traefik SSL Integration
services:
registry:
image: registry:2
volumes:
- registry-data:/var/lib/registry
- ./auth:/auth:ro
labels:
- "traefik.enable=true"
- "traefik.http.routers.registry.rule=Host(`registry.firma.de`)"
- "traefik.http.routers.registry.tls.certresolver=letsencrypt"
- "traefik.http.services.registry.loadbalancer.server.port=5000"
FAQ
Ist die Docker Registry genug oder soll ich Harbor nutzen?
Die Docker Registry ist minimal und ausreichend für einfaches Image-Hosting. Harbor bietet zusätzlich Vulnerability-Scanning, RBAC, Replication und ein Web-UI. Für >5 Entwickler: Harbor (Artikel #47 in dieser Blog-Serie).
Kann ich die Registry mit GitHub Actions / GitLab CI verbinden?
Ja. In CI/CD: docker login registry.firma.de:5000 -u user -p pass und dann normale Push/Pull-Befehle.
Fazit
Eine eigene Docker Registry ist in 15 Minuten eingerichtet und macht Teams unabhängig von Docker Hub.
Wir implementieren Docker-Infrastrukturen für Teams in Heidelberg, Mannheim und Rhein-Neckar. Anfragen.