容器仓库指南

镜像仓库对比

仓库提供商免费额度最适合
Docker HubDocker Inc.1 个私有仓库,拉取限速公开镜像、开源项目
Amazon ECRAWS500 MB/月(私有)AWS 原生负载,EKS/ECS
Google Artifact RegistryGCP0.5 GB 免费GCP/GKE 负载,多格式支持
Azure Container RegistryAzure无免费层Azure/AKS 负载,地理复制
GitHub Container RegistryGitHub公开免费,私有 1 GBGitHub Actions CI/CD、开源
Harbor自托管(CNCF)免费(自托管)离线环境、企业、多租户

镜像标签策略

# 语义化版本(推荐) myapp:latest # 始终指向最新(生产环境慎用!) myapp:1.2.3 # 不可变的具体版本 myapp:sha-abc1234 # git commit SHA(生产推荐) # 构建并推送多个标签 docker build -t myregistry/myapp:1.2.3 \ -t myregistry/myapp:1.2 \ -t myregistry/myapp:latest . docker push myregistry/myapp --all-tags

多架构构建(ARM + AMD64)

# 使用 buildx 构建多架构镜像 docker buildx create --use --name multiarch docker buildx inspect --bootstrap # 构建并推送 linux/amd64 + linux/arm64 docker buildx build \ --platform linux/amd64,linux/arm64 \ --tag myregistry/myapp:latest \ --push . # ECR 登录(AWS CLI) aws ecr get-login-password --region ap-east-1 \ | docker login --username AWS --password-stdin \ 123456789.dkr.ecr.ap-east-1.amazonaws.com # 创建 ECR 仓库(推送时自动扫描) aws ecr create-repository --repository-name myapp \ --image-scanning-configuration scanOnPush=true