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?

[no basic auth credentials] Amazon ECR に docker push できない問題 (私の場合)

Last updated at Posted at 2024-12-19

前提となる知識

基礎

Amazon ECR のリポジトリにイメージを push する手順は、コンソール上でリポジトリを選択し、「プッシュコマンドを表示」をクリックすると表示されます。
Photokako-mosaic-3b9nBAdxeIigHMQC.png
表示されるコマンドは次のようなものです。

$ aws ecr get-login-password --region ap-northeast-1 | docker login --username AWS --password-stdin 111122223333.dkr.ecr.ap-northeast-1.amazonaws.com
$ docker build -t hello-world . # . はDockerfileのあるディレクトリ 
$ docker tag hello-world:latest 111122223333.dkr.ecr.ap-northeast-1.amazonaws.com/hello-world:latest
$ docker push 111122223333.dkr.ecr.ap-northeast-1.amazonaws.com/hello-world:latest

AWS CLI へのログイン

本稿の要旨とは関係ありませんが、私は 公式ドキュメント でしきりに推奨されている aws configure sso でログインしています。

ログイン
$ aws configure sso
...(The rest is omitted.)
ログイン確認
$ aws s3 ls

今回使用したプロファイルは AdministratorAccess 権限を持つものとします。

問題

コンソールで示された、リポジトリにイメージを push する手順に従います。但し、dockerコマンドに対して sudo を追記します(伏線)。

$ aws ecr get-login-password --region ap-northeast-1 | docker login --username AWS --password-stdin 111122223333.dkr.ecr.ap-northeast-1.amazonaws.com
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
$ sudo docker build -t hello-world . 
$ sudo docker push 111122223333.dkr.ecr.ap-northeast-1.amazonaws.com/hello-world:latest
The push refers to repository [395453697891.dkr.ecr.ap-northeast-1.amazonaws.com/hello-world]
xxxxxxxxxxxx: Preparing 
xxxxxxxxxxxx: Preparing 
xxxxxxxxxxxx: Preparing 
xxxxxxxxxxxx: Preparing 
xxxxxxxxxxxx: Preparing 
xxxxxxxxxxxx: Waiting 
xxxxxxxxxxxx: Waiting 
xxxxxxxxxxxx: Waiting 
xxxxxxxxxxxx: Waiting 
no basic auth credentials

問題は no basic auth credentials です。
この問題については数多の先人たちが躓いているようで、それぞれの原因をそれぞれ解決していますが、私の場合に当てはまるものはありませんでした。
https://qiita.com/NaokiIshimura/items/1886dbd04631c3f7d0e1
https://qiita.com/harukisan/items/6f536e662b42ea2694a9
https://ja.stackoverflow.com/questions/59897/ecr%E3%81%B8%E3%81%AEdocker-push%E3%81%A7no-basic-auth-credentials%E3%81%A8%E3%81%84%E3%81%86%E3%82%A8%E3%83%A9%E3%83%BC
https://stackoverflow.com/questions/34689445/cant-push-image-to-amazon-ecr-fails-with-no-basic-auth-credentials
https://teratail.com/questions/243638
また、公式にもトラブルシューティングの記載がありますがこれを辿って勉強しても、基本的には、強力な権限の下で、コンソールに示される一連のコマンドに従えば上手く行く筈という結論しか得られませんでした。
2日間にわたる苦悩の末、私の場合も解決を得たので、公表して消化します。

解決

sudo docker login
つまり
$ aws ecr get-login-password --region ap-northeast-1 | sudo docker login --username AWS --password-stdin 111122223333.dkr.ecr.ap-northeast-1.amazonaws.com

私は dockersudo 無しのコマンドに設定していませんでした。しかし、此度の docker login では permission denied は出なかったし、設定ファイル ~/.docker/config.json も適切に記述されているようだったので、 sudo をつけないでもいいのだろうと無意識的に考えていました。このあたりの原理については未検証です。
以上、Docker 初心者が報告いたしました。

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?