1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Amazon ECR プライベートリポジトリからイメージを pull して別のプライベートリポジトリへ push を行う

Posted at

はじめに

Amazon ECS などを扱っていると、Amazon ECR プライベートリポジトリに pull や push を行う機会が多いと思います。
そこで、備忘録として扱うコマンドを 「pull → push」という流れでまとめておこうと思います。

前提

  • 対象リージョン
    • ap-rnotheast-1
  • インストール済みコマンド
    • dockerコマンド
    • aws-cliコマンド
  • 作業PC (シェル)
    • Mac (zsh)

ECR ログイン

まず、プライベートリポジトリの場合、対象となるAWSアカウントへログインしておく必要があります。

ecr login
% aws ecr get-login-password --region ap-northeast-1 | docker login --username AWS --password-stdin <AWS Accout ID>.dkr.ecr.ap-northeast-1.amazonaws.com
Login Succeeded

ECR からイメージを pull

docker pull
% docker pull <AWS Accout ID>.dkr.ecr.ap-northeast-1.amazonaws.com/src-repository:latest
latest: Pulling from repository
9986a736f7d3: Pull complete 
f55de6ab04a8: Pull complete 
0827d28a368d: Pull complete 
68f277b11af5: Pull complete 
ee80c16a5ca2: Pull complete 
6ce55efd2df5: Pull complete 
f34138022de3: Pull complete 
e0a706446bae: Pull complete 
39d1e73986c8: Pull complete 
e0f04c23873d: Pull complete 
Digest: sha256:d7841e9ec87db182a25e828e26f2995785cd6b9f29e5136327662f905cd2a780
Status: Downloaded newer image for <AWS Accout ID>.dkr.ecr.ap-northeast-1.amazonaws.com/src-repository:latest
<AWS Accout ID>.dkr.ecr.ap-northeast-1.amazonaws.com/src-repository:latest

What's next:
    View a summary of image vulnerabilities and recommendations → docker scout quickview <AWS Accout ID>.dkr.ecr.ap-northeast-1.amazonaws.com/src-repository:latest

pull の確認

イメージが pull できたかは docker images コマンドで確認できます。

docker images
% docker images                                                                 
REPOSITORY                                                    TAG       IMAGE ID       CREATED        SIZE
<AWS Accout ID>.dkr.ecr.ap-northeast-1.amazonaws.com/src-repository   latest    10005e405177   20 hours ago   144MB

タグ付け

push したいリポジトリのタグを付与します。

docker tag
% docker tag 10005e405177 <AWS Accout ID>.dkr.ecr.ap-northeast-1.amazonaws.com/dst-reository

タグ付け確認

タグが付与されていることの確認を行います。

docker images
% docker images                                                                      
REPOSITORY                                                    TAG       IMAGE ID       CREATED        SIZE
<AWS Accout ID>.dkr.ecr.ap-northeast-1.amazonaws.com/src-repository   latest    10005e405177   20 hours ago   144MB
<AWS Accout ID>.dkr.ecr.ap-northeast-1.amazonaws.com/dst-repository   latest    10005e405177   20 hours ago   144MB

イメージを ECR へ push

プライベートリポジトリへイメージを push します。
もし、AWSアカウントが異なるプライベートリポジトリへ push する際は改めてログインし直します。

docker push
% docker push <AWS Accout ID>.dkr.ecr.ap-northeast-1.amazonaws.com/dst-repository
Using default tag: latest
The push refers to repository [<AWS Accout ID>.dkr.ecr.ap-northeast-1.amazonaws.com/dst-repository]
4c23405945: Pushed 
baafb5615e: Pushed 
f6151dadd6: Pushed 
bf65225dde: Pushed 
d1b05c8061: Pushed 
81999a9585: Pushed 
317f6ada7f: Pushed 
55b2250d16: Pushed 
bd54bf34e2: Pushed 
651d22c234: Pushed 
latest: digest: sha256:d78ec2785cd6b9f29e5136327662f905cd2a780 size: 2408

以上で完了です。

おわりに

dev, stg, prod と環境ごとに AWS アカウントを分けることが多いと思います。
その際などに各環境へ展開する方法としてとても便利です。

参考

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?