aws ecr 在从 "Amazon Container Services" 复制 cmd 后说 "Cannot perform an interactive login from a non TTY device"

aws ecr saying "Cannot perform an interactive login from a non TTY device" after copied cmd from "Amazon Container Services"

我正在尝试在 AWS 的 ubuntu18.04 机器上设置 docker 亚马逊 ECR 图像,使用 view push commands of Amazon Container Services 提供的命令

,请注意我已经在我的 ubuntu18.04 上设置了 docker 并且 docker -v 的输出如下

ubuntu@ip-172-31-0-143:~$ docker -v
Docker version 19.03.7, build 7141c199a2

当我在 ubuntu18.04 上的 aws cli 上执行亚马逊容器服务提供的命令时,出现错误 错误:无法从非 TTY 设备执行交互式登录

我使用的命令是

aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin 8233251134332.dkr.ecr.us-east-2.amazonaws.com/gatling-lots

请注意,我已成功配置 awscli,我可以看到 详见aws s3 ls

这里是详细的错误日志

ubuntu@ip-172-31-0-143:~$ aws ecr get-login-password --region us-   
east-2 | docker login --username AWS --password-stdin 
823443336.dkr.ecr.us-west-2.amazonaws.com/gatling-lots
usage: aws [options] <command> <subcommand> [<subcommand> ...]      
[parameters]
 To see help text, you can run:

aws help
aws <command> help
aws <command> <subcommand> help
aws: error: argument operation: Invalid choice, valid choices are:

 batch-check-layer-availability           | batch-delete-image                      
 batch-get-image                          | complete-layer-upload                   
create-repository                        | delete-lifecycle-policy                 
delete-repository                        | delete-repository-policy                
 describe-images                          | describe-repositories                   
 get-authorization-token                  | get-download-url-for-layer              
 get-lifecycle-policy                     | get-lifecycle-policy-preview            
 get-repository-policy                    | initiate-layer-upload                   
 list-images                              | put-image                               
 put-lifecycle-policy                     | set-repository-policy                   
 start-lifecycle-policy-preview           | upload-layer-part                       
 get-login                                | help                                    
 Error: Cannot perform an interactive login from a non TTY device

的输出
ubuntu@ip-172-31-0-143:~$ (aws ecr get-login --no-include-email  --region us-east-2)

docker login -u AWS -p 

MzQxL2c0Yks4RjVxeDg9IiwidmVyc2lvbiI6IjIiLCJ0eXBlIjoiREFUQV9LRVkiLCJleHBpcmF0aW9uIjoxNTgzNjgzNDY5fQ== https://825251119036.dkr.ecr.us- east-2.amazonaws.com

您需要安装 AWS CLI 版本 2。 按照此 link

中的说明进行操作

问题不是 aws,而是 docker。解决方案是 docker 使用 -p 参数,并将 aws 登录调用包装到 -p 参数,如下所示:

docker login -u AWS -p $(aws ecr get-login-password --region the-region-you-are-in) xxxxxxxxx.dkr.ecr.the-region-you-are-in.amazonaws.com

这需要 AWS CLI 版本 2。

以下步骤解决了该问题。

$curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

$aws --version

aws-cli/2.0.30 Python/3.7.3 Linux/4.14.181-142.260.amzn2.x86_64 botocore/2.0.0dev34

$aws ecr get-login-password --region your_region | docker login --username AWS --password-stdin Account_ID.dkr.ecr.your_region.amazonaws.com

替换你的 Account IDRegion

此命令在 2020 年 10 月 6 日 bash 和 linux 中发挥作用:

linux@host:~$ $(aws ecr get-login --no-include-email)

那是因为

$ aws ecr get-login --no-include-email

给出以下输出:

docker login -u AWS -p xxxxxxxxxxxxx== https://xxx.dkr.ecr.eu-west-1.amazonaws.com

Devin 的回答是正确的。

但是还有一种方法。 docker 的更新版本需要此参数 --password-stdin

aws ecr get-login-password --region <YOUR_REGION> | docker login --username AWS --password-stdin  <ACCOUNT_ID>.dkr.ecr.<REGION>.amazonaws.com

我花了很长时间才弄清楚问题是我忘记了 运行 aws configure 并输入了正确的详细信息。那解决了我的问题。

另请记住,您不能在使用非分区 AWS 配置文件时登录分区区域(cn-*gov)。添加 --profile foo 以指定具有您指定区域的配置文件。

docker login 在您使用 --password-stdin 时打印此错误消息,但实际上并未将密码发送到命令的标准输入。

例如:

$ echo "" | docker login --password-stdin --username jorendorff
Error: Cannot perform an interactive login from a non TTY device

因此,| 管道符号之前的命令几乎任何类型的问题都会导致此无用的错误消息。

就我而言,我忘记在我的 AWS IAM 中添加 ECR 相关策略。 要添加政策,请遵循这些 steps.

我发现的问题是 AWS CLI v1 与 AWS CLI v2。我通过卸载 v1 并安装 AWS CLI v2 解决了这个问题。

在这种情况下不用担心。只需在终端中输入 'aws configure' 并粘贴 'aws_access_key_id' 和“aws_secret_access_key”等安全凭证,然后输入存储库区域和输出格式 'json'。

对我有用。

我知道这个问题已经有了答案,但是,这是我的经验。

这最初对我不起作用。

aws ecr get-login-password --region <your-region>| docker login --username AWS --password-stdin <your-container>

我在 GitLab 的变量下保存了 AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEY

但解决方案是取消选中保存在 GitLab 上的变量中的 Protected 标志。我不知道这种方法有多安全,但它确实对我有用。

我希望有一天这会对某人有所帮助。