Symptoms & Diagnosis
When executing docker login --password-stdin, the process often hangs indefinitely or returns an “unauthorized: incorrect username or password” error. This typically happens in CI/CD environments like Jenkins, GitHub Actions, or GitLab CI.
You might see the error message: “Error response from daemon: Get https://index.docker.io/v1/users/: unauthorized: incorrect username or password.” This is confusing because the same credentials work when entered manually.

Troubleshooting Guide
The most common cause of failure is a trailing newline character being passed into the pipe. Standard echo commands add a hidden \n which Docker includes as part of your actual password.
1. Fix Trailing Newlines
Instead of using echo, use printf to ensure no extra characters are sent. This is the most reliable method for passing secrets in bash scripts.
# The wrong way (adds a newline)
echo "my_password" | docker login -u my_username --password-stdin
# The right way (no newline)
printf "my_password" | docker login -u my_username --password-stdin
2. Handle Special Characters
If your password contains characters like $, !, or &, the shell may try to interpret them as variables. Always wrap your password in single quotes to prevent shell expansion.
# Use single quotes to protect special characters
cat my_password.txt | docker login -u my_username --password-stdin
3. Common Error Comparison
| Issue | Root Cause | Recommended Fix |
|---|---|---|
| Authentication Failed | Trailing newline or whitespace | Use printf or echo -n |
| Login Hangs | Waiting for TTY input | Ensure pipe is correctly formed |
| Credential Denied | Special character expansion | Wrap password in single quotes |
Prevention
- Use Environment Variables: Always store passwords in protected CI/CD secret variables rather than hardcoding them in scripts.
- Check Credential Helpers: If on a local machine, ensure
docker-credential-desktoporosxkeychainisn’t conflicting with your input. - Validate Input Source: If reading from a file, ensure the file was saved without a “POSIX newline” at the end.
- Update Docker: Older versions of Docker had intermittent bugs with stdin handling; ensure you are on a stable modern release.