container-registries
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseContainer Registries
容器镜像仓库
Store, manage, and distribute container images across cloud and self-hosted registries.
在云原生和自建镜像仓库中存储、管理和分发容器镜像。
When to Use This Skill
适用场景
Use this skill when:
- Pushing and pulling container images
- Configuring registry authentication
- Setting up image retention policies
- Managing private container registries
- Implementing image scanning and security
在以下场景中使用本技能:
- 推送和拉取容器镜像
- 配置镜像仓库认证
- 设置镜像保留策略
- 管理私有容器镜像仓库
- 实现镜像扫描与安全防护
Prerequisites
前置条件
- Docker or Podman installed
- Cloud CLI tools (AWS CLI, az, gcloud) for respective registries
- Appropriate IAM permissions
- 已安装 Docker 或 Podman
- 对应镜像仓库的云 CLI 工具(AWS CLI、az、gcloud)
- 具备合适的 IAM 权限
Docker Hub
Docker Hub
Authentication
认证
bash
undefinedbash
undefinedLogin
Login
docker login
docker login
Login with token
Login with token
echo "$DOCKER_TOKEN" | docker login -u username --password-stdin
undefinedecho "$DOCKER_TOKEN" | docker login -u username --password-stdin
undefinedPush/Pull Images
镜像推送/拉取
bash
undefinedbash
undefinedTag image
Tag image
docker tag myapp:latest username/myapp:latest
docker tag myapp:latest username/myapp:latest
Push
Push
docker push username/myapp:latest
docker push username/myapp:latest
Pull
Pull
docker pull username/myapp:latest
undefineddocker pull username/myapp:latest
undefinedAutomated Builds
自动构建
Configure in Docker Hub UI:
- Connect GitHub/Bitbucket repository
- Set build rules (branch → tag mapping)
- Configure build context and Dockerfile path
在 Docker Hub 界面中配置:
- 连接 GitHub/Bitbucket 仓库
- 设置构建规则(分支→标签映射)
- 配置构建上下文和 Dockerfile 路径
Amazon ECR
Amazon ECR
Setup
配置步骤
bash
undefinedbash
undefinedCreate repository
Create repository
aws ecr create-repository
--repository-name myapp
--image-scanning-configuration scanOnPush=true
--encryption-configuration encryptionType=AES256
--repository-name myapp
--image-scanning-configuration scanOnPush=true
--encryption-configuration encryptionType=AES256
aws ecr create-repository
--repository-name myapp
--image-scanning-configuration scanOnPush=true
--encryption-configuration encryptionType=AES256
--repository-name myapp
--image-scanning-configuration scanOnPush=true
--encryption-configuration encryptionType=AES256
Get registry URI
Get registry URI
REGISTRY=$(aws ecr describe-repositories
--repository-names myapp
--query 'repositories[0].repositoryUri'
--output text | cut -d'/' -f1)
--repository-names myapp
--query 'repositories[0].repositoryUri'
--output text | cut -d'/' -f1)
undefinedREGISTRY=$(aws ecr describe-repositories
--repository-names myapp
--query 'repositories[0].repositoryUri'
--output text | cut -d'/' -f1)
--repository-names myapp
--query 'repositories[0].repositoryUri'
--output text | cut -d'/' -f1)
undefinedAuthentication
认证
bash
undefinedbash
undefinedLogin (Docker)
Login (Docker)
aws ecr get-login-password --region us-east-1 |
docker login --username AWS --password-stdin $REGISTRY
docker login --username AWS --password-stdin $REGISTRY
aws ecr get-login-password --region us-east-1 |
docker login --username AWS --password-stdin $REGISTRY
docker login --username AWS --password-stdin $REGISTRY
Login with credential helper
Login with credential helper
Add to ~/.docker/config.json:
Add to ~/.docker/config.json:
{
"credHelpers": {
"123456789.dkr.ecr.us-east-1.amazonaws.com": "ecr-login"
}
}
undefined{
"credHelpers": {
"123456789.dkr.ecr.us-east-1.amazonaws.com": "ecr-login"
}
}
undefinedPush/Pull
镜像推送/拉取
bash
undefinedbash
undefinedTag and push
Tag and push
docker tag myapp:latest $REGISTRY/myapp:latest
docker push $REGISTRY/myapp:latest
docker tag myapp:latest $REGISTRY/myapp:latest
docker push $REGISTRY/myapp:latest
Pull
Pull
docker pull $REGISTRY/myapp:latest
undefineddocker pull $REGISTRY/myapp:latest
undefinedLifecycle Policy
生命周期策略
bash
undefinedbash
undefinedCreate lifecycle policy
Create lifecycle policy
aws ecr put-lifecycle-policy
--repository-name myapp
--lifecycle-policy-text '{ "rules": [ { "rulePriority": 1, "description": "Keep last 10 images", "selection": { "tagStatus": "any", "countType": "imageCountMoreThan", "countNumber": 10 }, "action": { "type": "expire" } } ] }'
--repository-name myapp
--lifecycle-policy-text '{ "rules": [ { "rulePriority": 1, "description": "Keep last 10 images", "selection": { "tagStatus": "any", "countType": "imageCountMoreThan", "countNumber": 10 }, "action": { "type": "expire" } } ] }'
undefinedaws ecr put-lifecycle-policy
--repository-name myapp
--lifecycle-policy-text '{ "rules": [ { "rulePriority": 1, "description": "Keep last 10 images", "selection": { "tagStatus": "any", "countType": "imageCountMoreThan", "countNumber": 10 }, "action": { "type": "expire" } } ] }'
--repository-name myapp
--lifecycle-policy-text '{ "rules": [ { "rulePriority": 1, "description": "Keep last 10 images", "selection": { "tagStatus": "any", "countType": "imageCountMoreThan", "countNumber": 10 }, "action": { "type": "expire" } } ] }'
undefinedRepository Policy
仓库策略
bash
undefinedbash
undefinedAllow cross-account access
Allow cross-account access
aws ecr set-repository-policy
--repository-name myapp
--policy-text '{ "Version": "2012-10-17", "Statement": [ { "Sid": "CrossAccountPull", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::OTHER_ACCOUNT:root" }, "Action": [ "ecr:GetDownloadUrlForLayer", "ecr:BatchGetImage" ] } ] }'
--repository-name myapp
--policy-text '{ "Version": "2012-10-17", "Statement": [ { "Sid": "CrossAccountPull", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::OTHER_ACCOUNT:root" }, "Action": [ "ecr:GetDownloadUrlForLayer", "ecr:BatchGetImage" ] } ] }'
undefinedaws ecr set-repository-policy
--repository-name myapp
--policy-text '{ "Version": "2012-10-17", "Statement": [ { "Sid": "CrossAccountPull", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::OTHER_ACCOUNT:root" }, "Action": [ "ecr:GetDownloadUrlForLayer", "ecr:BatchGetImage" ] } ] }'
--repository-name myapp
--policy-text '{ "Version": "2012-10-17", "Statement": [ { "Sid": "CrossAccountPull", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::OTHER_ACCOUNT:root" }, "Action": [ "ecr:GetDownloadUrlForLayer", "ecr:BatchGetImage" ] } ] }'
undefinedAzure Container Registry (ACR)
Azure Container Registry (ACR)
Setup
配置步骤
bash
undefinedbash
undefinedCreate registry
Create registry
az acr create
--resource-group mygroup
--name myregistry
--sku Standard
--admin-enabled false
--resource-group mygroup
--name myregistry
--sku Standard
--admin-enabled false
az acr create
--resource-group mygroup
--name myregistry
--sku Standard
--admin-enabled false
--resource-group mygroup
--name myregistry
--sku Standard
--admin-enabled false
Get login server
Get login server
az acr show --name myregistry --query loginServer -o tsv
undefinedaz acr show --name myregistry --query loginServer -o tsv
undefinedAuthentication
认证
bash
undefinedbash
undefinedLogin with Azure CLI
Login with Azure CLI
az acr login --name myregistry
az acr login --name myregistry
Login with service principal
Login with service principal
docker login myregistry.azurecr.io
-u $SP_APP_ID
-p $SP_PASSWORD
-u $SP_APP_ID
-p $SP_PASSWORD
docker login myregistry.azurecr.io
-u $SP_APP_ID
-p $SP_PASSWORD
-u $SP_APP_ID
-p $SP_PASSWORD
Get access token
Get access token
az acr login --name myregistry --expose-token
undefinedaz acr login --name myregistry --expose-token
undefinedPush/Pull
镜像推送/拉取
bash
undefinedbash
undefinedTag and push
Tag and push
docker tag myapp:latest myregistry.azurecr.io/myapp:latest
docker push myregistry.azurecr.io/myapp:latest
docker tag myapp:latest myregistry.azurecr.io/myapp:latest
docker push myregistry.azurecr.io/myapp:latest
ACR Build (build in cloud)
ACR Build (build in cloud)
az acr build
--registry myregistry
--image myapp:latest
--file Dockerfile .
--registry myregistry
--image myapp:latest
--file Dockerfile .
undefinedaz acr build
--registry myregistry
--image myapp:latest
--file Dockerfile .
--registry myregistry
--image myapp:latest
--file Dockerfile .
undefinedRetention Policy
保留策略
bash
undefinedbash
undefinedEnable retention policy
Enable retention policy
az acr config retention update
--registry myregistry
--status enabled
--days 30
--type UntaggedManifests
--registry myregistry
--status enabled
--days 30
--type UntaggedManifests
undefinedaz acr config retention update
--registry myregistry
--status enabled
--days 30
--type UntaggedManifests
--registry myregistry
--status enabled
--days 30
--type UntaggedManifests
undefinedGeo-Replication
地理复制
bash
undefinedbash
undefinedEnable replication
Enable replication
az acr replication create
--registry myregistry
--location westeurope
--registry myregistry
--location westeurope
az acr replication create
--registry myregistry
--location westeurope
--registry myregistry
--location westeurope
List replications
List replications
az acr replication list --registry myregistry
undefinedaz acr replication list --registry myregistry
undefinedGoogle Container Registry (GCR) / Artifact Registry
Google Container Registry (GCR) / Artifact Registry
Setup (Artifact Registry)
配置步骤(Artifact Registry)
bash
undefinedbash
undefinedCreate repository
Create repository
gcloud artifacts repositories create myrepo
--repository-format=docker
--location=us-central1
--description="Docker repository"
--repository-format=docker
--location=us-central1
--description="Docker repository"
undefinedgcloud artifacts repositories create myrepo
--repository-format=docker
--location=us-central1
--description="Docker repository"
--repository-format=docker
--location=us-central1
--description="Docker repository"
undefinedAuthentication
认证
bash
undefinedbash
undefinedConfigure Docker auth
Configure Docker auth
gcloud auth configure-docker us-central1-docker.pkg.dev
gcloud auth configure-docker us-central1-docker.pkg.dev
Or use credential helper
Or use credential helper
gcloud auth print-access-token |
docker login -u oauth2accesstoken --password-stdin
https://us-central1-docker.pkg.dev
docker login -u oauth2accesstoken --password-stdin
https://us-central1-docker.pkg.dev
undefinedgcloud auth print-access-token |
docker login -u oauth2accesstoken --password-stdin
https://us-central1-docker.pkg.dev
docker login -u oauth2accesstoken --password-stdin
https://us-central1-docker.pkg.dev
undefinedPush/Pull
镜像推送/拉取
bash
undefinedbash
undefinedTag for Artifact Registry
Tag for Artifact Registry
docker tag myapp:latest
us-central1-docker.pkg.dev/PROJECT_ID/myrepo/myapp:latest
us-central1-docker.pkg.dev/PROJECT_ID/myrepo/myapp:latest
docker tag myapp:latest
us-central1-docker.pkg.dev/PROJECT_ID/myrepo/myapp:latest
us-central1-docker.pkg.dev/PROJECT_ID/myrepo/myapp:latest
Push
Push
docker push us-central1-docker.pkg.dev/PROJECT_ID/myrepo/myapp:latest
docker push us-central1-docker.pkg.dev/PROJECT_ID/myrepo/myapp:latest
Pull
Pull
docker pull us-central1-docker.pkg.dev/PROJECT_ID/myrepo/myapp:latest
undefineddocker pull us-central1-docker.pkg.dev/PROJECT_ID/myrepo/myapp:latest
undefinedCleanup Policy
清理策略
bash
undefinedbash
undefinedCreate cleanup policy
Create cleanup policy
gcloud artifacts repositories set-cleanup-policies myrepo
--location=us-central1
--policy=policy.json
--location=us-central1
--policy=policy.json
gcloud artifacts repositories set-cleanup-policies myrepo
--location=us-central1
--policy=policy.json
--location=us-central1
--policy=policy.json
policy.json
policy.json
{
"name": "delete-old",
"action": {"type": "Delete"},
"condition": {
"olderThan": "30d",
"tagState": "untagged"
}
}
undefined{
"name": "delete-old",
"action": {"type": "Delete"},
"condition": {
"olderThan": "30d",
"tagState": "untagged"
}
}
undefinedGitHub Container Registry (GHCR)
GitHub Container Registry (GHCR)
Authentication
认证
bash
undefinedbash
undefinedLogin with PAT
Login with PAT
echo "$GITHUB_TOKEN" | docker login ghcr.io -u USERNAME --password-stdin
undefinedecho "$GITHUB_TOKEN" | docker login ghcr.io -u USERNAME --password-stdin
undefinedPush/Pull
镜像推送/拉取
bash
undefinedbash
undefinedTag
Tag
docker tag myapp:latest ghcr.io/OWNER/myapp:latest
docker tag myapp:latest ghcr.io/OWNER/myapp:latest
Push
Push
docker push ghcr.io/OWNER/myapp:latest
docker push ghcr.io/OWNER/myapp:latest
Pull
Pull
docker pull ghcr.io/OWNER/myapp:latest
undefineddocker pull ghcr.io/OWNER/myapp:latest
undefinedVisibility Settings
可见性设置
Configure in GitHub:
- Go to package settings
- Change visibility (public/private)
- Manage access for teams/users
在 GitHub 中配置:
- 进入包设置页面
- 修改可见性(公开/私有)
- 管理团队/用户的访问权限
Self-Hosted Registry
自建镜像仓库
Deploy with Docker
使用 Docker 部署
bash
undefinedbash
undefinedRun registry
Run registry
docker run -d -p 5000:5000
--name registry
-v registry-data:/var/lib/registry
registry:2
--name registry
-v registry-data:/var/lib/registry
registry:2
docker run -d -p 5000:5000
--name registry
-v registry-data:/var/lib/registry
registry:2
--name registry
-v registry-data:/var/lib/registry
registry:2
Configure TLS
Configure TLS
docker run -d -p 443:5000
--name registry
-v /certs:/certs
-v registry-data:/var/lib/registry
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt
-e REGISTRY_HTTP_TLS_KEY=/certs/domain.key
registry:2
--name registry
-v /certs:/certs
-v registry-data:/var/lib/registry
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt
-e REGISTRY_HTTP_TLS_KEY=/certs/domain.key
registry:2
undefineddocker run -d -p 443:5000
--name registry
-v /certs:/certs
-v registry-data:/var/lib/registry
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt
-e REGISTRY_HTTP_TLS_KEY=/certs/domain.key
registry:2
--name registry
-v /certs:/certs
-v registry-data:/var/lib/registry
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt
-e REGISTRY_HTTP_TLS_KEY=/certs/domain.key
registry:2
undefinedHarbor Registry
Harbor Registry
bash
undefinedbash
undefinedDownload Harbor
Download Harbor
wget https://github.com/goharbor/harbor/releases/download/v2.9.0/harbor-online-installer-v2.9.0.tgz
tar xzvf harbor-online-installer-v2.9.0.tgz
wget https://github.com/goharbor/harbor/releases/download/v2.9.0/harbor-online-installer-v2.9.0.tgz
tar xzvf harbor-online-installer-v2.9.0.tgz
Configure harbor.yml
Configure harbor.yml
Set hostname, https certificate, admin password
Set hostname, https certificate, admin password
Install
Install
./install.sh --with-trivy --with-chartmuseum
undefined./install.sh --with-trivy --with-chartmuseum
undefinedImage Security
镜像安全
Vulnerability Scanning
漏洞扫描
bash
undefinedbash
undefinedECR - Enable scan on push
ECR - Enable scan on push
aws ecr put-image-scanning-configuration
--repository-name myapp
--image-scanning-configuration scanOnPush=true
--repository-name myapp
--image-scanning-configuration scanOnPush=true
aws ecr put-image-scanning-configuration
--repository-name myapp
--image-scanning-configuration scanOnPush=true
--repository-name myapp
--image-scanning-configuration scanOnPush=true
Get scan results
Get scan results
aws ecr describe-image-scan-findings
--repository-name myapp
--image-id imageTag=latest
--repository-name myapp
--image-id imageTag=latest
aws ecr describe-image-scan-findings
--repository-name myapp
--image-id imageTag=latest
--repository-name myapp
--image-id imageTag=latest
ACR - Scan with Defender
ACR - Scan with Defender
az acr task create
--registry myregistry
--name scan-images
--cmd "mcr.microsoft.com/azure-cli az acr run-scan"
--registry myregistry
--name scan-images
--cmd "mcr.microsoft.com/azure-cli az acr run-scan"
undefinedaz acr task create
--registry myregistry
--name scan-images
--cmd "mcr.microsoft.com/azure-cli az acr run-scan"
--registry myregistry
--name scan-images
--cmd "mcr.microsoft.com/azure-cli az acr run-scan"
undefinedImage Signing
镜像签名
bash
undefinedbash
undefinedEnable content trust
Enable content trust
export DOCKER_CONTENT_TRUST=1
export DOCKER_CONTENT_TRUST=1
Sign image on push
Sign image on push
docker push myregistry/myapp:latest
docker push myregistry/myapp:latest
Verify signature
Verify signature
docker trust inspect myregistry/myapp:latest
undefineddocker trust inspect myregistry/myapp:latest
undefinedCommon Issues
常见问题
Issue: Authentication Expired
问题:认证过期
Problem: Push/pull fails with auth error
Solution: Re-run login command, check credential helper
问题:推送/拉取镜像时出现认证错误
解决方案:重新执行登录命令,检查凭证助手配置
Issue: Image Not Found
问题:镜像未找到
Problem: Pull fails with manifest unknown
Solution: Verify tag exists, check registry URL
问题:拉取镜像时出现 manifest unknown 错误
解决方案:验证标签是否存在,检查镜像仓库 URL
Issue: Push Permission Denied
问题:推送权限被拒绝
Problem: Cannot push to repository
Solution: Check IAM permissions, verify repository exists
问题:无法推送镜像至仓库
解决方案:检查 IAM 权限,确认仓库是否存在
Issue: Rate Limiting (Docker Hub)
问题:请求频率限制(Docker Hub)
Problem: Too many requests error
Solution: Authenticate for higher limits, use pull-through cache
问题:出现请求过多错误
解决方案:登录账号以获取更高限制,使用拉取缓存
Best Practices
最佳实践
- Enable vulnerability scanning on all repositories
- Implement lifecycle policies to manage storage costs
- Use immutable tags for production images
- Configure cross-region replication for availability
- Use service accounts/principals for CI/CD authentication
- Enable audit logging for compliance
- Implement image signing for supply chain security
- Use pull-through cache to avoid rate limits
- 为所有仓库启用漏洞扫描
- 实施生命周期策略以控制存储成本
- 为生产环境镜像使用不可变标签
- 配置跨区域复制以提升可用性
- 为 CI/CD 认证使用服务账号/主体
- 启用审计日志以满足合规要求
- 实施镜像签名以保障供应链安全
- 使用拉取缓存避免请求频率限制
Related Skills
相关技能
- docker-management - Building images
- container-scanning - Security scanning
- aws-iam - AWS permissions
- docker-management - 镜像构建
- container-scanning - 安全扫描
- aws-iam - AWS 权限