Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

docker login to Amazon ECR fails with: Cannot perform an interactive login from a non TTY device

ErrorCannot perform an interactive login from a non TTY device

Short answer

Docker asked for a password because none reached it, and a pipe or script has no keyboard to answer. Run the AWS command on its own first. If it prints a token, the login line is wrong. If it prints nothing, the AWS CLI is failing before Docker is even called.

  • Applies to AWS CLI 2, Docker Engine 28, Amazon ECR private registry
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Run the token command alone and send the output to nowhere. Success with no error means the AWS side works; an error means fix that before touching docker login. Use the region of your registry.

    aws ecr get-login-password --region us-east-1 > /dev/null && echo token-ok
  2. 2Match what you see, then jump to its fix

    1. 1The first step prints an AWS error, such as no credentials or an access denied message, instead of token-okThe AWS CLI fails, so docker login receives nothingFix
    2. 2The token command works alone, but the docker login part has no --password-stdinThe login line does not read the password from stdinFix
    3. 3aws --version shows a version older than the ones that have get-login-passwordThe AWS CLI is too old for get-login-passwordFix

What does the error look like?

  • Cannot perform an interactive login from a non TTY device

Cause 1 of 3

The AWS CLI fails, so docker login receives nothing

1Check

See which IAM identity the CLI is using, and with which profile and region. The token is created for that identity, and the region must be the one the registry lives in.

aws sts get-caller-identity
aws sts get-caller-identity --profile my-profile

2Fix

Use the profile and region that own the registry, in the same command that fetches the token.

aws ecr get-login-password --region us-east-1 --profile my-profile \
  | docker login --username AWS --password-stdin 123456789012.dkr.ecr.us-east-1.amazonaws.com

3Verify

The login command ends without an error, and a pull from the registry works.

docker pull 123456789012.dkr.ecr.us-east-1.amazonaws.com/my-repo:latest

Confirmed by docs.aws.amazon.com

Did this fix it?

Cause 2 of 3

The login line does not read the password from stdin

1Check

Compare your line with the one in the ECR guide: the username is the fixed word AWS, the password comes through the pipe, and docker login must be told to read it with --password-stdin.

grep -n "docker login" ./deploy.sh

2Fix

Add --password-stdin and give the registry address as the last argument, with no path after it.

aws ecr get-login-password --region us-east-1 \
  | docker login --username AWS --password-stdin 123456789012.dkr.ecr.us-east-1.amazonaws.com

3Verify

Run it from a script or CI step, where there is no terminal.

bash ./deploy.sh

Confirmed by docs.docker.com

Did this fix it?

Cause 3 of 3

The AWS CLI is too old for get-login-password

1Check

The command exists in AWS CLI version 2, and in version 1 from 1.17.10 onward. Older installs cannot create the token.

aws --version

2Fix

Install or upgrade to the latest AWS CLI, as the Amazon ECR guide advises for any login error.

# follow the AWS CLI v2 install guide for your OS, then check
aws --version

3Verify

Run the first step again.

aws ecr get-login-password --region us-east-1 > /dev/null && echo token-ok

Confirmed by docs.aws.amazon.com

Did this fix it?

How do I stop it coming back?

  • Keep the login line in one script and pass the region, profile and registry as variables.
  • ECR tokens last 12 hours, so log in again at the start of every CI job.
  • Use the Amazon ECR credential helper on machines that pull often, so no token pipe is needed.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.