{"id":"f0d2936cc1539533","repo":"docker/cli","slug":"error-username-is-required","errorCode":null,"errorMessage":"error: username is required","messagePattern":"error: username is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/registry.go","lineNumber":148,"sourceCode":"\n\t\tvar msg string\n\t\tdefaultUsername = strings.TrimSpace(defaultUsername)\n\t\tif defaultUsername == \"\" {\n\t\t\tmsg = \"Username: \"\n\t\t} else {\n\t\t\tmsg = fmt.Sprintf(\"Username (%s): \", defaultUsername)\n\t\t}\n\n\t\tvar err error\n\t\targUser, err = prompt.ReadInput(ctx, stdIn, cli.Out(), msg)\n\t\tif err != nil {\n\t\t\treturn registrytypes.AuthConfig{}, err\n\t\t}\n\t\tif argUser == \"\" {\n\t\t\targUser = defaultUsername\n\t\t}\n\t\tif argUser == \"\" {\n\t\t\treturn registrytypes.AuthConfig{}, errors.New(\"error: username is required\")\n\t\t}\n\t}\n\n\tisEmpty := strings.TrimSpace(argPassword) == \"\"\n\tif isEmpty {\n\t\trestoreInput, err := prompt.DisableInputEcho(stdIn)\n\t\tif err != nil {\n\t\t\treturn registrytypes.AuthConfig{}, err\n\t\t}\n\t\tdefer func() {\n\t\t\tif err := restoreInput(); err != nil {\n\t\t\t\t// TODO(thaJeztah): we should consider printing instructions how\n\t\t\t\t//  to restore this manually (other than restarting the shell).\n\t\t\t\t//  e.g., 'run stty echo' when in a Linux or macOS shell, but\n\t\t\t\t//  PowerShell and CMD.exe may need different instructions.\n\t\t\t\t_, _ = fmt.Fprintln(cli.Err(), \"Error: failed to restore terminal state to echo input:\", err)\n\t\t\t}\n\t\t}()","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/registry.go#L130-L166","documentation":"Raised by PromptUserForCredentials in the Docker CLI (cli/command/registry.go:148) when, after interactively prompting for a username, both the user's input and the default username (from previously stored credentials) are empty. A registry login cannot proceed without an identity, so the CLI aborts rather than sending an anonymous auth request.","triggerScenarios":"Running `docker login` (or any command that triggers credential prompting, e.g. `docker pull` against a private registry) where no --username flag was given, the interactive Username prompt is answered with an empty line, and no default username exists in the credential store for that registry.","commonSituations":"First-time login to a registry where the user just presses Enter at the Username prompt expecting a default; scripts piping empty input into `docker login`; fresh machines or CI runners with no ~/.docker/config.json entry for the registry so no default username can be offered.","solutions":["Type a non-empty username at the prompt, or pass it explicitly: docker login -u <username> <registry>","In scripts, always supply --username and use --password-stdin instead of relying on interactive prompts","For Docker Hub, consider a Personal Access Token with your Hub username (create at https://app.docker.com/settings)"],"exampleFix":"# before (prompt answered with empty input)\ndocker login registry.example.com\n# Username: <enter>\n# error: username is required\n\n# after\necho \"$REGISTRY_TOKEN\" | docker login registry.example.com -u myuser --password-stdin","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","registry","authentication","interactive-prompt"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}