Docker

[Docker] ECR Public Gallery에서 이미지 불러오기

박만자 2022. 6. 27. 17:18

도커 허브에서 이미지를 pull하여 사용하는 경우 유료 계정이 아니라면 이미지 pull에 대하여 횟수 제한이 걸려있습니다.

그래서 간혹가다 이미지 pull이 되지 않는 경우가 있습니다.

 

AWS아래 Public Registry를 통해  AWS 환경에서 무료로 제한없이 사용할 수 있는 Public 이미지들을 제공합니다.

https://gallery.ecr.aws/

 

ECR Public Gallery

Amazon ECR Public Gallery is a website that allows anyone to browse and search for public container images, view developer-provided details, and see pull commands

gallery.ecr.aws

 

AWS에서 제공하는 Public Registry를 사용함으로써 위와 같은 도커 허브의 단점을 보완할 수 있습니다.

 

이번 포스팅에서는 로컬 환경에서 어떻게 Public Registry에 인증하고 이미지를 pull 하는 법에 대해 포스팅하도록 하겠습니다.

 

로컬 환경에서 ECR Public Gallery 이미지 불러오기

ECR Public Gallery에서 이미지를 pull하기 위해서는 먼저 ecr-public:GetAuthorizationToken, sts:GetServiceBearerToken 권한을 가진 IAM User가 있어야 합니다.

 

IAM User 생성

IAM User를 생성한 후 아래와 같이 inline policy를 추가해 줍니다.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sts:GetServiceBearerToken"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "ecr-public:GetAuthorizationToken"
            ],
            "Resource": "*"
        }
    ]
}

 

ECR Public Gallery 인증

IAM User를 생성했다면 이제 ECR Public Gallery에 인증할 차례입니다.

 

그전에 먼저 aws configure 명령어로 위에서 생성한 IAM 계정을 AWS CLI에 설정해줍니다.

$ aws configure
AWS Access Key ID [****************ABCD]: AKIAVCGTB5Q4MO4TABCD
AWS Secret Access Key [****************ABCD]: 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
Default region name [ap-northeast-2]: ap-northeast-2
Default output format [json]: json

 

그다음 아래 명령어로 ECR Public Galley에 인증해줍니다. 리전은 꼭 us-east-1 으로 지정해줘야 합니다.

$ aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
Login Succeeded

Logging in with your password grants your terminal complete access to your account.
For better security, log in with a limited-privilege personal access token. Learn more at https://docs.docker.com/go/access-tokens/

 

 

이미지 pull

인증을 성공적으로 완료했다면 이제 ECR Public Gallery 에서 이미지를 pull 할 수 있습니다.

 

 

ECR Public Gallery에서 마음에 드는 이미지를 선택한 후 docker pull 명령어로 이미지를 pull 합니다.

$ docker pull public.ecr.aws/<repository-name>:<tag>

 

docker images 명령어로 이미지가 잘 pull 되었는지 확인해줍니다.

$ docker images
REPOSITORY                                TAG                   IMAGE ID       CREATED       SIZE
public.ecr.aws/sam/emulation-nodejs12.x   rapid-1.50.0-x86_64   a141bb084612   5 days ago    401MB
public.ecr.aws/sam/emulation-nodejs12.x   latest-x86_64         1604cc0f301a   12 days ago   384MB
public.ecr.aws/lambda/nodejs              16                    b560c0fcf7c3   12 days ago   479MB

 

참고