【備忘録】AWS ECRにdocker pushした際にno basic auth credentialsとなった場合の解決方法


問題点

ECRにコンテナイメージをdocker pushした際にno basic auth credentialsとなってしまい、pushが出来なかった。

$ aws ecr get-login --no-include-email --region ap-northeast-1
docker login -u AWS -p xxxxx== https://xxxxx.dkr.ecr.ap-northeast-1.amazonaws.com

$ docker login -u AWS -p xxxxx== https://xxxxx.dkr.ecr.ap-northeast-1.amazonaws.com
Login Succeeded

$ docker push xxxxx.dkr.ecr.ap-northeast-1.amazonaws.com/xxxxx:latest
The push refers to repository [xxxxx.dkr.ecr.ap-northeast-1.amazonaws.com/xxxxx]
dbee35a328d0: Preparing
77bf014019f2: Preparing
82cdb9879505: Preparing
...

no basic auth credentials

参考

Amazon ECR 使用時の Docker コマンドのエラーのトラブルシューティング - Amazon ECR

公式サイトのトラブルシューティングではno basic auth credentialsの原因がいくつか取り上げられていたが、自分の環境では該当しそうなものがなかった。

  • 別のリージョンに対して認証されている
  • トークンの有効期限が切れた。
  • wincred 認証情報マネージャーのバグ

原因

docker pushを実行してる環境のアクセスキーが別アカウントのものになっていた。

docker pushを実行してる環境のアクセスキー情報

$ aws configure
AWS Access Key ID [****************IUJD]:
AWS Secret Access Key [****************EuiN]:
Default region name [ap-northeast-1]:
Default output format [json]:

ECRを利用しているAWSコンソールのアクセスキー情報

解決方法

AWS CLIにECRを利用しているAWSアカウントのアクセスキーを設定して、 Dockerクライアントの認証とプッシュコマンドを再度実行したらdocker pushが成功した。

$ aws configure
AWS Access Key ID [****************IUJD]: ****************IXYQ
AWS Secret Access Key [****************EuiN]: ********************
Default region name [ap-northeast-1]:
Default output format [json]:
$ aws ecr get-login --no-include-email --region ap-northeast-1
docker login -u AWS -p xxxxx== https://xxxxx.dkr.ecr.ap-northeast-1.amazonaws.com

$ docker login -u AWS -p xxxxx== https://xxxxx.dkr.ecr.ap-northeast-1.amazonaws.com
Login Succeeded

$ docker push xxxxx.dkr.ecr.ap-northeast-1.amazonaws.com/xxxxx:latest
The push refers to repository [xxxxx.dkr.ecr.ap-northeast-1.amazonaws.com/xxxxx]
dbee35a328d0: Pushed
77bf014019f2: Pushed
82cdb9879505: Pushed
...

latest: digest: sha256:d4c79d7f9b26762a139b150fdf65fa55c47d1673f4cc55659ed9969ddf03db8b size: 5947