Passer au contenu principal

Production (Docker)

Registry privé

Dépendre de Docker Hub en production, c'est dépendre d'un service externe avec ses rate limits et ses pannes. Un registry privé apporte le contrôle d'accès, la rétention des images, la proximité réseau et l'indépendance vis-à-vis de l'extérieur.

Registry officiel (distribution)

# compose.yml — registry minimaliste
services:
  registry:
    image: registry:2
    restart: unless-stopped
    ports:
      - "5000:5000"
    volumes:
      - registry-data:/var/lib/registry
    environment:
      REGISTRY_STORAGE_DELETE_ENABLED: "true"

volumes:
  registry-data:
# Pousser une image vers le registry local
docker tag myapp:latest localhost:5000/myapp:latest
docker push localhost:5000/myapp:latest

# Lister les images
curl http://localhost:5000/v2/_catalog

# Lister les tags d'une image
curl http://localhost:5000/v2/myapp/tags/list

Le registry sans authentification ne doit pas être exposé sur Internet. Mettre un reverse proxy (nginx, Caddy) avec TLS et basic auth devant.

Harbor

Harbor est le registry cloud-native de référence pour les environnements on-premise. Il ajoute : RBAC, scan de vulnérabilités (Trivy intégré), replication, webhooks, garbage collection.

# Installation via Helm (recommandé sur K8s) ou via script offline
wget https://github.com/goharbor/harbor/releases/download/v2.11.0/harbor-offline-installer-v2.11.0.tgz
tar xzf harbor-offline-installer-v2.11.0.tgz
cd harbor

# Copier et éditer la configuration
cp harbor.yml.tmpl harbor.yml
vim harbor.yml  # configurer hostname, TLS, DB

./install.sh --with-trivy

GitHub Container Registry

# Auth avec token GitHub
echo $CR_PAT | docker login ghcr.io -u USERNAME --password-stdin

# Rendre l'image publique ou privée via les settings du repository GitHub
docker push ghcr.io/monorg/monapp:latest

Garbage collection

# Sur le registry officiel : garbage collect les blobs non référencés
docker exec registry bin/registry garbage-collect   /etc/docker/registry/config.yml --delete-untagged

Sans garbage collection régulière, le stockage du registry grossit indéfiniment, même après suppression des tags. Automatiser via cron.