Docker Registries
Overview
Section titled “Overview”Automated Docker image publication to multiple container registries.
Workflow: .github/workflows/docker-hub.yml
Registries: Docker Hub, GitHub Container Registry (ghcr.io)
Platforms: linux/amd64, linux/arm64
Supported Registries
Section titled “Supported Registries”1. Docker Hub (docker.io)
Section titled “1. Docker Hub (docker.io)”Default public registry
# Pull imagedocker pull username/rust-template:latestdocker pull username/rust-template:0.1.0
# Run containerdocker run -it username/rust-template:latestURL: https://hub.docker.com/r/username/rust-template
2. GitHub Container Registry (ghcr.io)
Section titled “2. GitHub Container Registry (ghcr.io)”Integrated with GitHub
# Pull imagedocker pull ghcr.io/username/rust-template:latestdocker pull ghcr.io/username/rust-template:0.1.0
# Run containerdocker run -it ghcr.io/username/rust-template:latestURL: https://github.com/username/rust-template/pkgs/container/rust-template
3. AWS ECR (Elastic Container Registry)
Section titled “3. AWS ECR (Elastic Container Registry)”Amazon’s private registry
# Loginaws ecr get-login-password --region us-east-1 | \ docker login --username AWS --password-stdin \ 123456789.dkr.ecr.us-east-1.amazonaws.com
# Pull imagedocker pull 123456789.dkr.ecr.us-east-1.amazonaws.com/rust-template:latestSetup: Add to workflow:
- name: Login to Amazon ECR uses: aws-actions/amazon-ecr-login@v2
- name: Build and push to ECR uses: docker/build-push-action@v6 with: push: true tags: | 123456789.dkr.ecr.us-east-1.amazonaws.com/rust-template:${{ github.sha }} 123456789.dkr.ecr.us-east-1.amazonaws.com/rust-template:latest4. Google Artifact Registry
Section titled “4. Google Artifact Registry”Google Cloud’s registry
# Logingcloud auth configure-docker us-docker.pkg.dev
# Pull imagedocker pull us-docker.pkg.dev/PROJECT/rust-template/rust-template:latestSetup: Add to workflow:
- name: Authenticate to Google Cloud uses: google-github-actions/auth@v2 with: credentials_json: ${{ secrets.GCP_CREDENTIALS }}
- name: Setup Cloud SDK uses: google-github-actions/setup-gcloud@v2
- name: Configure Docker run: gcloud auth configure-docker us-docker.pkg.dev
- name: Build and push uses: docker/build-push-action@v6 with: push: true tags: us-docker.pkg.dev/PROJECT/rust-template/rust-template:latest5. Azure Container Registry (ACR)
Section titled “5. Azure Container Registry (ACR)”Microsoft Azure’s registry
# Loginaz acr login --name myregistry
# Pull imagedocker pull myregistry.azurecr.io/rust-template:latestSetup: Add to workflow:
- name: Login to Azure uses: azure/login@v2 with: creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Login to ACR uses: azure/docker-login@v2 with: login-server: myregistry.azurecr.io username: ${{ secrets.ACR_USERNAME }} password: ${{ secrets.ACR_PASSWORD }}
- name: Build and push uses: docker/build-push-action@v6 with: push: true tags: myregistry.azurecr.io/rust-template:latest6. Quay.io
Section titled “6. Quay.io”Red Hat’s public registry
# Pull imagedocker pull quay.io/username/rust-template:latestSetup: Add to workflow:
- name: Login to Quay.io uses: docker/login-action@v3 with: registry: quay.io username: ${{ secrets.QUAY_USERNAME }} password: ${{ secrets.QUAY_TOKEN }}
- name: Build and push uses: docker/build-push-action@v6 with: push: true tags: quay.io/username/rust-template:latestImage Tagging Strategy
Section titled “Image Tagging Strategy”Semantic Versioning
Section titled “Semantic Versioning”tags: | type=semver,pattern={{version}} # 0.1.0 type=semver,pattern={{major}}.{{minor}} # 0.1 type=semver,pattern={{major}} # 0 type=sha # sha-abc1234Results:
latest- Always points to newest release0.1.0- Specific version0.1- Latest patch in minor version0- Latest minor in major versionsha-abc1234- Git commit SHA
Branch Tagging
Section titled “Branch Tagging”tags: | type=ref,event=branch # main, develop type=ref,event=pr # pr-123Configuration
Section titled “Configuration”Required Secrets
Section titled “Required Secrets”Docker Hub
Section titled “Docker Hub”- Go to https://hub.docker.com/settings/security
- Create Access Token
- Add GitHub secrets:
DOCKERHUB_USERNAMEDOCKERHUB_TOKEN
GitHub Container Registry
Section titled “GitHub Container Registry”No setup needed - uses GITHUB_TOKEN automatically.
Make package public:
- Go to package settings
- Change visibility to Public
Multi-Platform Builds
Section titled “Multi-Platform Builds”Current platforms: linux/amd64, linux/arm64
Add more platforms:
platforms: linux/amd64,linux/arm64,linux/arm/v7Supported architectures:
linux/amd64- x86_64 (Intel/AMD)linux/arm64- ARM 64-bit (Apple Silicon, ARM servers)linux/arm/v7- ARM 32-bit (Raspberry Pi)linux/386- x86 32-bitlinux/ppc64le- PowerPClinux/s390x- IBM Z
Image Metadata
Section titled “Image Metadata”Labels
Section titled “Labels”Automatically added via docker/metadata-action:
LABEL org.opencontainers.image.source="https://github.com/USER/REPO"LABEL org.opencontainers.image.description="Modern Rust template"LABEL org.opencontainers.image.licenses="MIT"LABEL org.opencontainers.image.version="0.1.0"Attestations
Section titled “Attestations”Add provenance and SBOM:
- name: Build and push uses: docker/build-push-action@v6 with: provenance: true sbom: trueRegistry-Specific Features
Section titled “Registry-Specific Features”Docker Hub
Section titled “Docker Hub”- Auto README sync - Updates description from GitHub README
- Webhooks - Trigger on image push
- Vulnerability scanning - Free for public images
- Download stats - Track pull metrics
GitHub Container Registry
Section titled “GitHub Container Registry”- Tight integration - Links to repository automatically
- Package permissions - Inherit repo permissions
- Free for public - Unlimited public images
- Packages API - Programmatic access
AWS ECR
Section titled “AWS ECR”- Private by default - No public registry
- Scanning - Amazon Inspector integration
- Lifecycle policies - Auto-delete old images
- IAM integration - AWS permissions
Security Best Practices (how-to)
Section titled “Security Best Practices (how-to)”The registry list, tagging, and metadata sections above are reference; this section and the troubleshooting snippets below are task-oriented guidance.
1. Use Specific Tags
Section titled “1. Use Specific Tags”# ❌ Bad - Can break on updatesFROM rust:latest
# ✅ Good - Pinned versionFROM rust:1.92-slim2. Sign Images
Section titled “2. Sign Images”- name: Install cosign uses: sigstore/cosign-installer@v3
- name: Sign image run: | cosign sign --yes \ username/rust-template:${{ github.sha }}3. Scan for Vulnerabilities
Section titled “3. Scan for Vulnerabilities”- name: Run Trivy uses: aquasecurity/trivy-action@master with: image-ref: username/rust-template:latest format: 'sarif' output: 'trivy-results.sarif'4. Use Minimal Base Images
Section titled “4. Use Minimal Base Images”# ✅ Distroless - No shell, minimal attack surfaceFROM gcr.io/distroless/cc-debian12
# ✅ Alpine - Small but has shellFROM alpine:latest
# ⚠️ Debian slim - Larger but more compatibleFROM debian:12-slimCache Optimization
Section titled “Cache Optimization”GitHub Actions Cache
Section titled “GitHub Actions Cache”cache-from: type=ghacache-to: type=gha,mode=maxBenefits:
- Reuses layers between builds
- Faster builds (minutes → seconds)
- No external cache storage needed
Registry Cache
Section titled “Registry Cache”cache-from: type=registry,ref=username/rust-template:buildcachecache-to: type=registry,ref=username/rust-template:buildcache,mode=maxTroubleshooting
Section titled “Troubleshooting”Authentication Fails
Section titled “Authentication Fails”# Verify tokenecho $DOCKERHUB_TOKEN | docker login -u $DOCKERHUB_USERNAME --password-stdin
# Check ghcr.io permissionsecho $GITHUB_TOKEN | docker login ghcr.io -u $GITHUB_ACTOR --password-stdinMulti-Platform Build Fails
Section titled “Multi-Platform Build Fails”# Check QEMUdocker run --rm --privileged multiarch/qemu-user-static --reset -p yes
# Build specific platformdocker buildx build --platform linux/arm64 .Image Too Large
Section titled “Image Too Large”# Analyze layersdocker history username/rust-template:latest
# Use dive for interactive analysisdive username/rust-template:latestOptimization tips:
- Use multi-stage builds
- Combine RUN commands
- Remove build artifacts
- Use .dockerignore
Monitoring
Section titled “Monitoring”Download Metrics
Section titled “Download Metrics”Docker Hub:
# Via Hub APIcurl https://hub.docker.com/v2/repositories/username/rust-template/GitHub Container Registry:
# Via GitHub APIgh api /users/username/packages/container/rust-templateVulnerability Alerts
Section titled “Vulnerability Alerts”Enable on:
- Docker Hub: Settings → Vulnerability Scanning
- GitHub: Settings → Security → Dependabot
- AWS ECR: Auto-enabled with Inspector