docker login to Amazon ECR fails with: Cannot perform an interactive login from a non TTY device
Cannot perform an interactive login from a non TTY deviceShort 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.
Fix it fast
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-ok2Match what you see, then jump to its fix
- 1
The 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
The token command works alone, but the docker login part has no --password-stdinThe login line does not read the password from stdinFix - 3
aws --version shows a version older than the ones that have get-login-passwordThe AWS CLI is too old for get-login-passwordFix
- 1
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-profile2Fix
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.com3Verify
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:latestConfirmed by docs.aws.amazon.com
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.sh2Fix
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.com3Verify
Run it from a script or CI step, where there is no terminal.
bash ./deploy.shConfirmed by docs.docker.com
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 --version2Fix
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 --version3Verify
Run the first step again.
aws ecr get-login-password --region us-east-1 > /dev/null && echo token-okConfirmed by docs.aws.amazon.com
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:
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- RaheebA consumer app shipped to both stores from one Flutter codebase on a .NET and Azure back end.
Related fixes
Servers
docker push is denied: requested access to the resource is denied
push access denied, repository does not exist or may require authorization
The registry refused the push.
3 causes, each with a fixServers
sam local fails: Running AWS SAM projects locally requires Docker
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
sam local start-api and sam local invoke run your function inside a Docker container, so SAM stops if it cannot talk to Docker.
3 causes, each with a fixServers
The Java SDK finds no AWS credentials on an EC2 instance or in a container on it
InstanceProfileCredentialsProvider()
The SDK walks a fixed list of credential sources and the EC2 instance role is the last one.
3 causes, each with a fixServers
cdk deploy fails in a GitLab job with spawnSync docker ENOENT
code: 'ENOENT'
ENOENT means the operating system found no docker program to run.
3 causes, each with a fixServers
docker push to Amazon ECR stops with: no basic auth credentials
no basic auth credentials
Docker has no stored login for the registry host in your image tag.
2 causes, each with a fixServers
A Lambda container image crashes locally with KeyError: AWS_LAMBDA_RUNTIME_API
KeyError: 'AWS_LAMBDA_RUNTIME_API'
The Lambda runtime interface client reads AWS_LAMBDA_RUNTIME_API at start-up.
2 causes, each with a fix