Docker Registry: Seu RepositΓ³rio Privado π¦
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β DOCKER REGISTRY: PRIVATE IMAGE REPOSITORY β
β β
β "Seu prΓ³prio cantinho seguro para guardar imagens" β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Fundamentos do Registry π
O que é um Registry?
Serviço de armazenamento e distribuição
Repositório de imagens Docker
Sistema de versionamento
Controle de acesso
Tipos de Registry
Docker Hub (Público)
Registry Privado
Cloud Providers
Amazon ECR
Google Container Registry
Azure Container Registry
Implantação do Registry π
Registry Local
# Iniciar registry local
docker run -d \
-p 5000:5000 \
--name registry \
registry:2
# Testar registry
curl http://localhost:5000/v2/_catalog
Registry com TLS
# Gerar certificados
openssl req -newkey rsa:4096 -nodes -sha256 \
-keyout certs/domain.key -x509 -days 365 \
-out certs/domain.crt
# Iniciar registry seguro
docker run -d \
-p 5000:5000 \
--name registry \
-v $(pwd)/certs:/certs \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \
-e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \
registry:2
Operações Básicas π οΈ
Push e Pull
# Tag local
docker tag nginx:latest localhost:5000/my-nginx
# Push para registry local
docker push localhost:5000/my-nginx
# Pull do registry local
docker pull localhost:5000/my-nginx
Autenticação
# Configurar autenticaΓ§Γ£o bΓ‘sica
docker run -d \
-p 5000:5000 \
--name registry \
-v $(pwd)/auth:/auth \
-e "REGISTRY_AUTH=htpasswd" \
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
-e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" \
registry:2
# Login no registry
docker login localhost:5000
Configuração Avançada βοΈ
Storage Backends
storage:
filesystem:
rootdirectory: /var/lib/registry
s3:
accesskey: awsaccesskey
secretkey: awssecretkey
region: us-east-1
bucket: docker-registry
Garbage Collection
# Executar garbage collection
docker exec registry bin/registry garbage-collect \
/etc/docker/registry/config.yml
Alta Disponibilidade π
Registry em Cluster
version: '3'
services:
registry1:
image: registry:2
ports:
- "5000:5000"
environment:
REGISTRY_HTTP_TLS_CERTIFICATE: /certs/domain.crt
REGISTRY_HTTP_TLS_KEY: /certs/domain.key
volumes:
- registry-data:/var/lib/registry
- ./certs:/certs
Load Balancing
upstream docker-registry {
server registry1:5000;
server registry2:5000;
}
server {
listen 443 ssl;
server_name registry.example.com;
ssl_certificate /etc/nginx/certs/domain.crt;
ssl_certificate_key /etc/nginx/certs/domain.key;
location / {
proxy_pass http://docker-registry;
}
}
Segurança e Políticas π
Image Signing
# Habilitar DCT (Docker Content Trust)
export DOCKER_CONTENT_TRUST=1
# Assinar imagem
docker trust sign myregistry.com/app:1.0
Access Control
auth:
token:
realm: https://auth.example.com/token
service: container_registry
issuer: auth_token_issuer
Monitoramento π
Métricas Básicas
# Verificar status
curl -X GET http://localhost:5000/debug/vars
# Monitorar espaΓ§o
du -sh /var/lib/registry
Prometheus Integration
metrics:
enabled: true
address: localhost:5001
Troubleshooting π
Logs e Debug
# Verificar logs
docker logs registry
# Aumentar verbosidade
docker run -d \
-e REGISTRY_LOG_LEVEL=debug \
registry:2
Problemas Comuns
Certificados Inválidos
# Adicionar certificado ao sistema cp domain.crt /usr/local/share/ca-certificates/ update-ca-certificatesProblemas de Storage
# Verificar permissΓ΅es chown -R 100:100 /var/lib/registry
Registry UI π₯οΈ
Docker Registry UI
# Iniciar interface web
docker run -d \
-p 8080:8080 \
--name registry-ui \
-e REGISTRY_URL=http://registry:5000 \
joxit/docker-registry-ui
CI/CD Integration π
GitHub Actions
jobs:
push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Login to Registry
run: docker login -u ${{ secrets.REGISTRY_USER }} -p ${{ secrets.REGISTRY_PASS }}
- name: Build and Push
run: |
docker build -t registry.example.com/app:${{ github.sha }} .
docker push registry.example.com/app:${{ github.sha }}
Waifu Registry Tips π«
Checklist de Produção β
[x] TLS configurado
[x] Autenticação habilitada
[x] Storage backend redundante
[x] Monitoramento ativo
[x] Backup automatizado
[x] Políticas de retenção
[x] Rate limiting configurado
Recursos Adicionais π
Documentação
Ferramentas
16 abril 2025