Maaz Zindani

Loading the index…

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

docker login prints a warning about --password and how to log in without it

ErrorWARNING! Using --password via the CLI is insecure. Use --password-stdin.

Short answer

Docker prints this warning whenever you give docker login a real value with --password or -p, because the secret then sits in shell history and process lists. Pipe the secret into docker login with --username and --password-stdin instead. The login still works either way; the warning is only a nudge.

  • Applies to Docker Engine 28, Docker CLI 28
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find where the password is passed as an argument. In a shell, search your history; in CI, search the pipeline files for the flag.

    grep -rn -E 'docker login.*(--password|-p )' . --include='*.yml' --include='*.yaml' --include='*.sh'
  2. 2Match what you see, then jump to its fix

    1. 1WARNING! Using --password via the CLI is insecure. Use --password-stdin.The secret is passed as an argument with --password or -pFix
    2. 2the --password-stdin option requires --username to be set--password-stdin is used without --usernameFix
    3. 3conflicting options: cannot specify both --password and --password-stdin--password and --password-stdin are both on the same commandFix
    4. 4Docker stores the credential in ~/.docker/config.json after a successful loginThe login works, but the credential is stored as base64 in config.jsonFix

What does the error look like?

  • WARNING! Using --password via the CLI is insecure. Use --password-stdin.
  • conflicting options: cannot specify both --password and --password-stdin
  • the --password-stdin option requires --username to be set

Cause 1 of 4

The secret is passed as an argument with --password or -p

1Check

Look for docker login commands that carry the secret after --password or -p. The CLI prints the warning whenever that value is not empty and is not a single dash.

grep -rn 'docker login' . | grep -E -- '--password |-p '

2Fix

Send the secret on standard input and tell Docker to read it there. In CI, read it from a masked variable, never type it inline.

echo "$REGISTRY_TOKEN" | docker login --username my-user --password-stdin
# or from a file that only you can read
cat ~/my_password.txt | docker login --username my-user --password-stdin

3Verify

The command prints Login Succeeded and no warning line.

echo "$REGISTRY_TOKEN" | docker login --username my-user --password-stdin

Confirmed by docs.docker.com

Did this fix it?

Cause 2 of 4

--password-stdin is used without --username

1Check

Reading the secret from stdin only replaces the password. The CLI still needs the user name, and an empty value fails too.

echo "username is [$REGISTRY_USER]"

2Fix

Pass --username with a non-empty value. In CI, make sure the user variable is defined for that job.

echo "$REGISTRY_TOKEN" | docker login --username "$REGISTRY_USER" --password-stdin

3Verify

The login succeeds with no usage error.

echo "$REGISTRY_TOKEN" | docker login --username "$REGISTRY_USER" --password-stdin

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 3 of 4

--password and --password-stdin are both on the same command

1Check

A script was half converted: the new flag was added but the old --password argument was left in place.

grep -rn -- '--password-stdin' . | grep -E -- '--password [^-]|-p '

2Fix

Delete the old --password value. The only form that may stay next to stdin is a single dash, which also means read from stdin.

echo "$REGISTRY_TOKEN" | docker login --username my-user --password-stdin

3Verify

The command runs without the conflicting options error.

echo "$REGISTRY_TOKEN" | docker login --username my-user --password-stdin

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 4 of 4

The login works, but the credential is stored as base64 in config.json

1Check

Without a credential store, Docker keeps the login in config.json in base64, which is not encryption.

cat ~/.docker/config.json

2Fix

Configure an external credential store through the credsStore key, then log in again. Docker says an external store is more secure than the config file.

# ~/.docker/config.json (use the helper installed on your OS)
{
  "credsStore": "osxkeychain"
}

3Verify

After logging in again, the auths entry no longer holds an encoded secret.

cat ~/.docker/config.json

Confirmed by docs.docker.com

Did this fix it?

How do I stop it coming back?

  • Use --password-stdin in every script and pipeline from the start.
  • Give CI a registry token or personal access token with only the scope it needs, not a user password.
  • Keep the secret in the CI secret store and let the runner mask it in logs.
  • Use a credential store on developer machines.

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.