Aws ecr 说“无法从非 TTY 设备执行交互式登录”

利用 Amazon Container Servicesview push commands提供的命令,尝试在 AWS 的 ubuntu18.04机器上建立亚马逊 ECR 的 Docker 映像 view push commands of amazon container services

请注意,我已经设置了 docker对我的 ubuntu18.04和也输出的 docker -v是如下

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

当我在 ubuntu18.04的 aws cli 上执行由 Amazon 容器服务提供的命令时,我得到错误消息 错误: 无法从非 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
146316 次浏览

You need to install AWS CLI version 2. Follow the instructions in this link

The problem is not aws but docker. The solution is on docker to use the -p parameter, and wrap the aws login call to the -p parameter as such:

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

And this requires AWS CLI version 2.

Below steps are resolve that issue.

$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

Replace your Account ID and Region.

This command does the trick in bash and linux at 2020/10/06:

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

That's because

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

Gives the following output:

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

Devin's answer is correct.

But there is one more way. The updated version of docker requires this parameter --password-stdin.

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

it took me forever to figure out that the issue was that I forgot to run aws configure and enter the right details. That solved my issue.

Also remember you cannot log into partitioned regions (cn-* or gov) while using a non-partitioned AWS profile. Add --profile foo to specify a profile with your designated region.

docker login prints this error message when you use --password-stdin, but don't actually send a password to the command's stdin.

For example:

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

Therefore, almost any kind of problem with the command before the | pipe symbol will result in this unhelpful error message.

In my case, I forgot to add ECR related policy in my AWS IAM. To add a policy follow these steps.

The issue I found is AWS CLI v1 vs AWS CLI v2. I resolved this by uninstalling v1 and installing AWS CLI v2.

No worries in this case. Just type 'aws configure' in your terminal and paste the security credentials such as 'aws_access_key_id' and 'aws_secret_access_key'and then type the region of the repository and the output format as 'json'.

It worked for me.

I know this question is answered already, but, this was my experience.

This didn't work for me initially.

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

I had the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY saved under variables in GitLab.

But the solution was to uncheck the Protected flag from the variables saved on GitLab. I don't know how secure this approach is, but, it did work for me.

I hope this would help someone one day.

This answer is for similar error getting for github actions. Please try this and let me know if this works

- name: Docker login
uses: docker/login-action@v2
with:
username: $\{\{ secrets.DOCKER_USERNAME }}
password: $\{\{ secrets.DOCKER_PASSWORD }}```

All the above did not work for me on a windows OS. However windows (10) was suggesting updates. I applied the Update & Restart and when I executed the login command

aws ecr get-login-password --region your_region_code | sudo docker login --username AWS --password-stdin numeric-account-id.dkr.ecr.your-region-code.amazonaws.com

Everything worked again normally.

I got this error on Ubuntu 18.04 after my AWS CLI was automatically updated.

I solved it by reverting it back to the previous version using this command:

sudo apt-get install awscli=1.14.44-1ubuntu1 -V

You need to authorize your EC2 machine to access AWS services either by

  • running aws configure and providing the right details OR
  • Give your EC2 machine a role to enable it access ECR

Also if you run your docker commands with sudo, then add sudo before the docker command as shown below

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

Cheers.