$npx -y skills add BagelHole/DevOps-Security-Agent-Skills --skill container-registriesManage container registries including ECR, ACR, GCR, and Docker Hub. Push and pull images, configure authentication, set up repository policies, and implement image lifecycle management. Use when working with container image storage and distribution.
| 1 | # Container Registries |
| 2 | |
| 3 | Store, manage, and distribute container images across cloud and self-hosted registries. |
| 4 | |
| 5 | ## When to Use This Skill |
| 6 | |
| 7 | Use this skill when: |
| 8 | - Pushing and pulling container images |
| 9 | - Configuring registry authentication |
| 10 | - Setting up image retention policies |
| 11 | - Managing private container registries |
| 12 | - Implementing image scanning and security |
| 13 | |
| 14 | ## Prerequisites |
| 15 | |
| 16 | - Docker or Podman installed |
| 17 | - Cloud CLI tools (AWS CLI, az, gcloud) for respective registries |
| 18 | - Appropriate IAM permissions |
| 19 | |
| 20 | ## Docker Hub |
| 21 | |
| 22 | ### Authentication |
| 23 | |
| 24 | ```bash |
| 25 | # Login |
| 26 | docker login |
| 27 | |
| 28 | # Login with token |
| 29 | echo "$DOCKER_TOKEN" | docker login -u username --password-stdin |
| 30 | ``` |
| 31 | |
| 32 | ### Push/Pull Images |
| 33 | |
| 34 | ```bash |
| 35 | # Tag image |
| 36 | docker tag myapp:latest username/myapp:latest |
| 37 | |
| 38 | # Push |
| 39 | docker push username/myapp:latest |
| 40 | |
| 41 | # Pull |
| 42 | docker pull username/myapp:latest |
| 43 | ``` |
| 44 | |
| 45 | ### Automated Builds |
| 46 | |
| 47 | Configure in Docker Hub UI: |
| 48 | 1. Connect GitHub/Bitbucket repository |
| 49 | 2. Set build rules (branch → tag mapping) |
| 50 | 3. Configure build context and Dockerfile path |
| 51 | |
| 52 | ## Amazon ECR |
| 53 | |
| 54 | ### Setup |
| 55 | |
| 56 | ```bash |
| 57 | # Create repository |
| 58 | aws ecr create-repository \ |
| 59 | --repository-name myapp \ |
| 60 | --image-scanning-configuration scanOnPush=true \ |
| 61 | --encryption-configuration encryptionType=AES256 |
| 62 | |
| 63 | # Get registry URI |
| 64 | REGISTRY=$(aws ecr describe-repositories \ |
| 65 | --repository-names myapp \ |
| 66 | --query 'repositories[0].repositoryUri' \ |
| 67 | --output text | cut -d'/' -f1) |
| 68 | ``` |
| 69 | |
| 70 | ### Authentication |
| 71 | |
| 72 | ```bash |
| 73 | # Login (Docker) |
| 74 | aws ecr get-login-password --region us-east-1 | \ |
| 75 | docker login --username AWS --password-stdin $REGISTRY |
| 76 | |
| 77 | # Login with credential helper |
| 78 | # Add to ~/.docker/config.json: |
| 79 | { |
| 80 | "credHelpers": { |
| 81 | "123456789.dkr.ecr.us-east-1.amazonaws.com": "ecr-login" |
| 82 | } |
| 83 | } |
| 84 | ``` |
| 85 | |
| 86 | ### Push/Pull |
| 87 | |
| 88 | ```bash |
| 89 | # Tag and push |
| 90 | docker tag myapp:latest $REGISTRY/myapp:latest |
| 91 | docker push $REGISTRY/myapp:latest |
| 92 | |
| 93 | # Pull |
| 94 | docker pull $REGISTRY/myapp:latest |
| 95 | ``` |
| 96 | |
| 97 | ### Lifecycle Policy |
| 98 | |
| 99 | ```bash |
| 100 | # Create lifecycle policy |
| 101 | aws ecr put-lifecycle-policy \ |
| 102 | --repository-name myapp \ |
| 103 | --lifecycle-policy-text '{ |
| 104 | "rules": [ |
| 105 | { |
| 106 | "rulePriority": 1, |
| 107 | "description": "Keep last 10 images", |
| 108 | "selection": { |
| 109 | "tagStatus": "any", |
| 110 | "countType": "imageCountMoreThan", |
| 111 | "countNumber": 10 |
| 112 | }, |
| 113 | "action": { |
| 114 | "type": "expire" |
| 115 | } |
| 116 | } |
| 117 | ] |
| 118 | }' |
| 119 | ``` |
| 120 | |
| 121 | ### Repository Policy |
| 122 | |
| 123 | ```bash |
| 124 | # Allow cross-account access |
| 125 | aws ecr set-repository-policy \ |
| 126 | --repository-name myapp \ |
| 127 | --policy-text '{ |
| 128 | "Version": "2012-10-17", |
| 129 | "Statement": [ |
| 130 | { |
| 131 | "Sid": "CrossAccountPull", |
| 132 | "Effect": "Allow", |
| 133 | "Principal": { |
| 134 | "AWS": "arn:aws:iam::OTHER_ACCOUNT:root" |
| 135 | }, |
| 136 | "Action": [ |
| 137 | "ecr:GetDownloadUrlForLayer", |
| 138 | "ecr:BatchGetImage" |
| 139 | ] |
| 140 | } |
| 141 | ] |
| 142 | }' |
| 143 | ``` |
| 144 | |
| 145 | ## Azure Container Registry (ACR) |
| 146 | |
| 147 | ### Setup |
| 148 | |
| 149 | ```bash |
| 150 | # Create registry |
| 151 | az acr create \ |
| 152 | --resource-group mygroup \ |
| 153 | --name myregistry \ |
| 154 | --sku Standard \ |
| 155 | --admin-enabled false |
| 156 | |
| 157 | # Get login server |
| 158 | az acr show --name myregistry --query loginServer -o tsv |
| 159 | ``` |
| 160 | |
| 161 | ### Authentication |
| 162 | |
| 163 | ```bash |
| 164 | # Login with Azure CLI |
| 165 | az acr login --name myregistry |
| 166 | |
| 167 | # Login with service principal |
| 168 | docker login myregistry.azurecr.io \ |
| 169 | -u $SP_APP_ID \ |
| 170 | -p $SP_PASSWORD |
| 171 | |
| 172 | # Get access token |
| 173 | az acr login --name myregistry --expose-token |
| 174 | ``` |
| 175 | |
| 176 | ### Push/Pull |
| 177 | |
| 178 | ```bash |
| 179 | # Tag and push |
| 180 | docker tag myapp:latest myregistry.azurecr.io/myapp:latest |
| 181 | docker push myregistry.azurecr.io/myapp:latest |
| 182 | |
| 183 | # ACR Build (build in cloud) |
| 184 | az acr build \ |
| 185 | --registry myregistry \ |
| 186 | --image myapp:latest \ |
| 187 | --file Dockerfile . |
| 188 | ``` |
| 189 | |
| 190 | ### Retention Policy |
| 191 | |
| 192 | ```bash |
| 193 | # Enable retention policy |
| 194 | az acr config retention update \ |
| 195 | --registry myregistry \ |
| 196 | --status enabled \ |
| 197 | --days 30 \ |
| 198 | --type UntaggedManifests |
| 199 | ``` |
| 200 | |
| 201 | ### Geo-Replication |
| 202 | |
| 203 | ```bash |
| 204 | # Enable replication |
| 205 | az acr replication create \ |
| 206 | --registry myregistry \ |
| 207 | --location westeurope |
| 208 | |
| 209 | # List replications |
| 210 | az acr replication list --registry myregistry |
| 211 | ``` |
| 212 | |
| 213 | ## Google Container Registry (GCR) / Artifact Registry |
| 214 | |
| 215 | ### Setup (Artifact Registry) |
| 216 | |
| 217 | ```bash |
| 218 | # Create repository |
| 219 | gcloud artifacts repositories create myrepo \ |
| 220 | --repository-format=docker \ |
| 221 | --location=us-central1 \ |
| 222 | --description="Docker repository" |
| 223 | ``` |
| 224 | |
| 225 | ### Authentication |
| 226 | |
| 227 | ```bash |
| 228 | # Configure Docker auth |
| 229 | gcloud auth configure-docker us-central1-docker.pkg.dev |
| 230 | |
| 231 | # Or use credential helper |
| 232 | gcloud auth print-access-token | \ |
| 233 | docker login -u oauth2accesstoken --password-stdin \ |
| 234 | https://us-central1-docker.pkg.dev |
| 235 | ``` |
| 236 | |
| 237 | ### Push/Pull |
| 238 | |
| 239 | ```bash |
| 240 | # Tag for Artifact Registry |
| 241 | docker tag myapp:latest \ |
| 242 | us-central1-docker.pkg.dev/PROJECT_ID/myrepo/myapp:latest |