ECR Commands¶
Manage Elastic Container Registry repositories and images.
copy-image is the useful one: it pulls an image from any registry (Docker Hub, GHCR, another ECR account) and pushes it into ECR, optionally creating the repository first. It shells out to the local Docker daemon, so Docker must be running.
Commands¶
ecr copy-image¶
Copy a Docker image from any registry to AWS ECR.
| Option | Value | Description |
|---|---|---|
--tag |
TEXT |
Tag to use for the image in ECR (default: latest) |
--region |
TEXT |
AWS region for ECR repository (default: current region) |
--create-repo |
flag | Create ECR repository if it doesn't exist |
--force |
flag | Force overwrite if image already exists |
ecr create-repository¶
Create a new ECR repository.
| Option | Value | Description |
|---|---|---|
--region |
TEXT |
AWS region to create repository in (default: current region) |
--scan-on-push |
flag | Enable image scanning on push |
--image-tag-mutability |
MUTABLE | IMMUTABLE |
Image tag mutability setting (default: MUTABLE) |
--encryption-type |
AES256 | KMS |
Encryption type for the repository (default: AES256) |
ecr delete-repository¶
Delete an ECR repository.
| Option | Value | Description |
|---|---|---|
--region |
TEXT |
AWS region where the repository is located (default: current region) |
--force |
flag | Force delete repository even if it contains images |
--confirm |
flag | Skip confirmation prompt |
ecr get-login¶
Get Docker login command for ECR or execute login directly.
| Option | Value | Description |
|---|---|---|
--region |
TEXT |
AWS region for ECR login (default: current region) |
--print-command |
flag | Print the docker login command instead of executing it |
ecr list-images¶
List images in an ECR repository.
| Option | Value | Description |
|---|---|---|
--region |
TEXT |
AWS region where the repository is located (default: current region) |
--max-results |
INTEGER |
Maximum number of images to list (default: 100) |
--output-file |
TEXT |
Output file for images list (supports .json, .yaml, .csv) |
ecr list-repositories¶
List ECR repositories with details.
| Option | Value | Description |
|---|---|---|
--region |
TEXT |
AWS region to list repositories from (default: current region) |
--all-regions |
flag | List repositories from all regions |
--output-file |
TEXT |
Output file for repositories list (supports .json, .yaml, .csv) |
Examples¶
# Repositories in this region, and everywhere
aws-cloud-utilities ecr list-repositories
aws-cloud-utilities ecr list-repositories --all-regions --output-file repos.csv
# Images in a repository
aws-cloud-utilities ecr list-images my-app --max-results 50
# Create a repository with scanning on and immutable tags
aws-cloud-utilities ecr create-repository my-app --scan-on-push --image-tag-mutability IMMUTABLE
# KMS-encrypted repository
aws-cloud-utilities ecr create-repository my-app --encryption-type KMS
# Mirror a public image into ECR, creating the repo if needed
aws-cloud-utilities ecr copy-image nginx:latest my-nginx --create-repo --tag stable
# Docker login: run it, or just print the command
aws-cloud-utilities ecr get-login
aws-cloud-utilities ecr get-login --print-command
# Delete a repository and everything in it
aws-cloud-utilities ecr delete-repository my-app --force --confirm
Notes¶
copy-image requires a running Docker daemon and enough disk space for the image layers. It pulls,
retags, and pushes.
delete-repository needs --force to delete a repository that still contains images, and --confirm
to skip the interactive prompt. Both are required for unattended use.
Related¶
- IAM Commands - review the roles that can push to ECR
- Inventory Commands - full resource inventory