aws ecsでdocker imageのpull/pushが出来るようになるまで
前提
既にAWS上でECRを使用するための設定が完了していること
手順の概要
aws cliの認証設定
~/.aws/configure ~/.aws/credentials
の2つのファイルを設定する。直接編集してもいいし下記のコマンドでも設定できる。
aws configure --profile sample
中身はこんな感じ。
~/.aws/configure
[profile sample] region = ap-northeast-1 output = json
~/.aws/credentials
[sample] aws_access_key_id =*********** aws_secret_access_key = ********** output = json
profileはオプションだが、設定した場合は[sample]
という形でsampleプロファルが保存される。defaultも設定できる。
プロファイルの選択
プロファイルは環境変数AWS_DEFAULT_PROFILE
にプロファイル名を瀬底することで行える。
set -x AWS_DEFAULT_PROFILE sample
※ fish shellを用いている
docker clientにてログインする
aws 2.0 or newer
以下を実行すれば良いです。 こちらのコマンドはシェルに依存しません。 <aws_account_id>は数字です。
aws ecr get-login-password --region <resion> | docker login --username AWS --password-stdin <aws_account_id>.dkr.ecr.us-east-1.amazonaws.com
以前の方法は aws2以降は非対応
これは以前の方法です。 aws cliがdocker clientでのlogin commandを生成してくれるが、bash形式なので、bashで実行する。
aws ecr get-login --no-include-email --region ap-northeast-1 | bash -
これでaws のecsでdocker imageのpull/pushが出来るようになる。