🐳

Amazon ECRのプライベートレジストリのDockerイメージのローカルでのPull/Push

に公開

概要

CodeBuildでビルドされているDockerイメージをローカルにPULLしたかった時の備忘録です。

結論

これだけです。ECRでログイン用のTokenを発行できます。12時間有効です。

$ aws ecr get-login-password --region region | docker login --username AWS --password-stdin aws_account_id.dkr.ecr.region.amazonaws.com
$ docker pull aws_account_id.dkr.ecr.us-west-2.amazonaws.com/repository:tag

https://docs.aws.amazon.com/ja_jp/codebuild/latest/userguide/sample-docker-section.html

ちなみに、CodeBuild で Docker Image をビルドする手順にもありますね。

version: 0.2

phases:
  pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
  build:
    commands:
      - echo Build started on `date`
      - echo Building the Docker image...          
      - docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .
      - docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG      
  post_build:
    commands:
      - echo Build completed on `date`
      - echo Pushing the Docker image...
      - docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG

参考

https://docs.aws.amazon.com/ja_jp/AmazonECR/latest/userguide/docker-pull-ecr-image.html

https://docs.aws.amazon.com/ja_jp/AmazonECR/latest/userguide/registry_auth.html

Discussion