LoginSignup
1
1

More than 3 years have passed since last update.

【AWS】ECSリポジトリにローカルのDockerをプッシュできないときの対処方法

Posted at

環境

Docker 19.03.8
macOS 10.15.4

IAMユーザーの作成

IAMユーザーを作成し、その後にアクセスキーを設定します。

terminal
$ aws configure
AWS Access Key ID [****************]: (credencialsAccess key ID)
AWS Secret Access Key [****************]: (credencialsSecret access key)
Default region name [ap-northeast-1]: ap-northeast-1
Default output format [json]: json

そして$ aws configure listを実行します。

terminal
$ aws configure list
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                <not set>             None    None
access_key     (credencialsAccess key ID)      env    
secret_key     (credencialsSecret access key)  env    
    region           ap-northeast-1      config-file    ~/.aws/config

※しかしこのときにセキュリティ的に伏せていますが$ aws configure$ aws configure listのアクセスキー及び、シークレットアクセスキーが一致していない前提です

認証トークンを取得し、レジストリに対して Docker クライアントを認証しようとするものの...

terminal
$ aws ecr get-login-password --region ap-northeast-1 | docker login --username AWS --password-stdin (アカウントID).dkr.ecr.ap-northeast-1.amazonaws.com

An error occurred (UnrecognizedClientException) when calling the GetAuthorizationToken operation: The security token included in the request is invalid.

このエラーの内容は認証情報周りの設定に問題があることが原因だと言うことがわかりました。アクセスキーとシークレットアクセスキーがenvになっているのでおそらくどこかで環境変数にアクセスキーとシークレットアクセスキーを設定していると考えました。

.bash_profileを確認する

.bash_profileの中を確認してみます。

terminal
$ open -a TextEdit ~/.bash_profile

$ aws configure listで確認されたアクセスキーとシークレットアクセスキーの末尾と一致するアクセスキーとシークレットアクセスキーが表示されましたので削除します。

ターミナルを閉じて再度開いてから$ aws configure listを実行すると.bash_profileのアクセスキーとシークレットアクセスキーが優先され、IAMユーザー認証情報が実行できなかった場合にこれでエラーが解消されます。

それ以外のアクセスキーとシークレットアクセスキーが優先されていた場合は...

下記のコマンドを実行し一度リセットします。

terminal
$ mv ~/.aws/credentials /tmp/credentials.bak
$ mv ~/.aws/config /tmp/config.bak
# credentialとconfigを削除するコマンド

そして一度ターミナルを閉じてから再度開いて$ aws configureを実行して再設定する方法もあります。

以上が【ECSリポジトリにローカルのDockerをプッシュできないときの対処方法】になります^_^

1
1
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
1
1