0
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?

ECRへのpushで少し詰まった

Last updated at Posted at 2025-03-12

awsのスイッチロール先のecrにpushする際に詰まったので備忘録として記録します。

ECRレポジトリを作成

まずecrにレポジトリを作成する。
次にawsのセキュリティ認証でアクセスキーを作成する
この時、アクセスキーとシークレットアクセスキーをコピーしてcsvをダウンロードする。

ローカルのcredentialとconfig

次に vi ~/.aws/credentials でアクセスキーとシークレットアクセスキーを記入

[hoge-deploy]
aws_access_key_id = ........
aws_secret_access_key = ........

次に vi ~/.aws/config でprofileを記入

[profile hoge-deploy]
region = ap-northeast-1
output = json

ECRにpush

そのあとはログインしてpushする。
アクセスキーが複数ある場合は、ログインの際に—profile [profile名]をつけるのを忘れずに。
つけなかったらdefaultが優先される

$aws ecr get-login-password --region ap-northeast-1 --profile hoge-deploy | docker login --username AWS --password-stdin xxxx.dkr.ecr.xxxx.amazonaws.com
$docker tag hoge:latest xxxx.dkr.ecr.xxxx.amazonaws.com/hoge:latest
$docker push xxxx.dkr.ecr.xxxx.amazonaws.com/hoge:latest

ec2がecrからpullしたい時には、ec2にロールを付与しないといけない。
今回はpullのみ必要だったので AmazonEC2ContainerRegistryReadOnly を付与しました。
EC2のコンテナ → アクション → セキュリティ → IAMロールを変更 → AmazonEC2ContainerRegistryReadOnly を選択して、変更をクリック

0
0
0

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
0
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?