LoginSignup
7

More than 5 years have passed since last update.

ECR push をやってみた

Last updated at Posted at 2018-04-16

はじめに

弊社環境の ECR に docker push を行うにあたりちょっと詰まったのでメモ。

前提

config と credential は以下

~/.aws/config
[default]
region = ap-northeast-1

~/.aws/credential
[default]
aws_access_key_id = my_access_key_id
aws_secret_access_key = my_secret_access_key

[production/developer]
role_arn = arn:aws:iam::000000000000:role/developer
mfa_serial = arn:aws:iam::000000000000:mfa/my_user_name
source_profile = default

[production/admin]
role_arn = arn:aws:iam::000000000000:role/admin
mfa_serial = arn:aws:iam::000000000000:mfa/my_user_name
source_profile = default

ECR push までの手順

IAM でアカウントが払い出されていて適切に権限も付与されていることを想定しています。
手順と言っても、ECR にプッシュコマンドを表示とあるのでほぼそのとおりでいい。MFAを設定していると認証を求められる。6桁のアレを入力。

$ aws ecr get-login --no-include-email --region ap-northeast-1 --profile production/developer

↑を叩くとコマンドが返却されるのでそのままコピペして実行。--profile の指定に注意。楽したいなら eval です。下記は例。

`eval $(aws ecr get-login --registry-ids ${OWN_AWS_ID} --region ap-northeast-1 --no-include-email)`
Login Succeeded

となれば OK。docker build もします。

$ docker build --build-arg HOGE_TOKEN=HOGEHOGE -t fuga .

私の環境だとトークンを渡してあげないといけなかったので --build-arg で環境変数を渡した。ちなみにこれは image 内に残らないのでセキュリティも担保されている。

最後に push。

$ docker push 000000000000.dkr.ecr.ap-northeast-1.amazonaws.com/fuga:latest

push する前に ECR でリポジトリを作っておくのを忘れずに。docker build 時に tag 打つのも忘れずに。

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
7