이미지가 푸시될 때 ECR이 자동으로 생성될 수 있습니다
Source: Dev.to
Overview
Amazon Elastic Container Registry (ECR)는 존재하지 않는 레포지토리를 대상으로 이미지를 푸시하면 자동으로 레포지토리를 생성할 수 있습니다. 이 기능은 레포지토리를 미리 생성할 필요 없이 워크플로를 간소화합니다.
Prerequisites
- ECR에 이미지를 푸시할 수 있는 권한이 있는 AWS 계정.
- AWS CLI가 설치되고 구성되어 있음.
- Docker(또는 Docker Buildx)가 설치되어 있음.
Steps
1. (Optional) Create a repository‑creation template
네이밍 접두사를 강제하거나 기본 레포지토리 설정(예: 이미지 태그 가변성)을 지정하고 싶다면, ECR 콘솔이나 AWS CLI를 통해 Repository Create template을 생성합니다. 템플릿에서는 이미지 태그가 mutable(가변)인지 immutable(불변)인지도 지정할 수 있습니다.
2. Build the Docker image
docker buildx build -t test-auto-create --platform=linux/amd64 .
3. Authenticate Docker to ECR
aws ecr get-login-password --region us-west-2 |
docker login --username AWS --password-stdin xxxxxxxxxxxx.dkr.ecr.us-west-2.amazonaws.com
4. Tag the image for the target repository
docker tag 3413614e55cd xxxxxxxxxxxx.dkr.ecr.us-west-2.amazonaws.com/test-auto-create:latest
5. Push the image
docker push xxxxxxxxxxxx.dkr.ecr.us-west-2.amazonaws.com/test-auto-create:latest
푸시가 완료되면 ECR이 자동으로 test-auto-create 레포지토리를 생성합니다.
Verification
푸시 전후에 다음 명령을 실행하여 레포지토리가 생성된 것을 확인합니다:
aws ecr describe-repositories --registry-id xxxxxxxxxxxx
푸시 후 샘플 출력:
{
"repositoryArn": "arn:aws:ecr:us-west-2:xxxxxxxxxxxx:repository/test-auto-create",
"registryId": "xxxxxxxxxxxx",
"repositoryName": "test-auto-create",
"repositoryUri": "xxxxxxxxxxxx.dkr.ecr.us-west-2.amazonaws.com/test-auto-create",
"createdAt": "2025-12-21T12:39:57.362000+09:00",
"imageTagMutability": "IMMUTABLE",
"imageScanningConfiguration": {
"scanOnPush": false
},
"encryptionConfiguration": {
"encryptionType": "AES256"
}
}
Additional Notes
- 자동 생성은 pull‑through cache 레포지토리에도 적용되어 ECR Public이나 Docker Hub에서 이미지를 캐시하기가 더 쉬워집니다.
- 레포지토리 설정(예: 태그 가변성, 푸시 시 스캔, 암호화)은 레포지토리‑생성 템플릿을 통해 전역적으로 제어할 수 있습니다. 템플릿이 정의되지 않은 경우 기본 설정이 적용됩니다.