docker/cli · error

username is empty

Error message

username is empty

What it means

Thrown by verifyLoginFlags when the --username flag was explicitly changed but resolves to an empty string, e.g. 'docker login -u ""'. The flag-level guard (lines 83-84) treats an explicitly-empty username as invalid.

Solutions

  1. Provide a non-empty username value.
  2. Quote and check the variable before invoking the command.
  3. Use --password-stdin with a guaranteed non-empty username.

Example fix

# before
docker login -u ""
# after
USER=${USER:?empty}; docker login -u "$USER" --password-stdin
Defensive patterns

Strategy: validation

Validate before calling

// Reject an explicitly empty --username
if flags.Changed("username") && strings.TrimSpace(opts.user) == "" {
    return fmt.Errorf("--username must not be empty")
}

Prevention

When it happens

Trigger: Running 'docker login -u ""' or 'docker login --username=' (empty value) at the flag-parsing stage.

Common situations: Passing an unset shell variable unquoted as empty: 'docker login -u $EMPTY_VAR'; misconfigured env in scripts.

Related errors


AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07). Data as JSON: /api/errors/f1b15b87b44c5ba0. Report an issue: GitHub.

Appendix: source

Thrown at cli/command/registry/login.go:84

	flags.BoolVar(&opts.passwordStdin, "password-stdin", false, "Take the Password or Personal Access Token (PAT) from stdin")

	return cmd
}

// verifyLoginFlags validates flags set on the command.
//
// TODO(thaJeztah); combine with verifyLoginOptions, but this requires rewrites of many tests.
func verifyLoginFlags(flags *pflag.FlagSet, opts loginOptions) error {
	if flags.Changed("password-stdin") || opts.password == "-" {
		if flags.Changed("password") && opts.password != "-" {
			return errors.New("conflicting options: cannot specify both --password and --password-stdin")
		}
		if !flags.Changed("username") {
			return errors.New("the --password-stdin option requires --username to be set")
		}
	}
	if flags.Changed("username") && opts.user == "" {
		return errors.New("username is empty")
	}
	if flags.Changed("password") && opts.password == "" {
		return errors.New("password is empty")
	}
	return nil
}

// readSecretFromStdin reads the secret from r and returns it as a string.
// It trims terminal line-endings (LF, CRLF, or CR), which may be added when
// inputting interactively or piping input. The value is otherwise treated as
// opaque, preserving any other whitespace, including newlines, per [NIST SP 800-63B §5.1.1.2].
// Note that trimming whitespace may still happen elsewhere (see [NIST SP 800-63B (revision 4) §3.1.1.2]);
//
// > Verifiers **MAY** make limited allowances for mistyping (e.g., removing
// > leading and trailing whitespace characters before verification, allowing
// > the verification of passwords with differing cases for the leading character)
//
// [NIST SP 800-63B §5.1.1.2]: https://pages.nist.gov/800-63-3/sp800-63b.html#memsecretver

View on GitHub (pinned to 4f84911bfe)