{"id":"38309d0683be8351","repo":"docker/cli","slug":"specify-only-one-h","errorCode":null,"errorMessage":"specify only one -H","messagePattern":"specify only one -H","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/cli.go","lineNumber":593,"sourceCode":"\tops = append(defaultOps, ops...)\n\n\tcli := &DockerCli{baseCtx: context.Background()}\n\tfor _, op := range ops {\n\t\tif err := op(cli); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\treturn cli, nil\n}\n\nfunc getServerHost(hosts []string, defaultToTLS bool) (string, error) {\n\tswitch len(hosts) {\n\tcase 0:\n\t\treturn dopts.ParseHost(defaultToTLS, os.Getenv(client.EnvOverrideHost))\n\tcase 1:\n\t\treturn dopts.ParseHost(defaultToTLS, hosts[0])\n\tdefault:\n\t\treturn \"\", errors.New(\"specify only one -H\")\n\t}\n}\n\n// UserAgent returns the default user agent string used for making API requests.\nfunc UserAgent() string {\n\treturn \"Docker-Client/\" + version.Version + \" (\" + runtime.GOOS + \")\"\n}\n\nvar defaultStoreEndpoints = []store.NamedTypeGetter{\n\tstore.EndpointTypeGetter(docker.DockerEndpoint, func() any { return &docker.EndpointMeta{} }),\n}\n\n// RegisterDefaultStoreEndpoints registers a new named endpoint\n// metadata type with the default context store config, so that\n// endpoint will be supported by stores using the config returned by\n// DefaultContextStoreConfig.\nfunc RegisterDefaultStoreEndpoints(ep ...store.NamedTypeGetter) {\n\tdefaultStoreEndpoints = append(defaultStoreEndpoints, ep...)","sourceCodeStart":575,"sourceCodeEnd":611,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/cli.go#L575-L611","documentation":"Raised by getServerHost in cli/command/cli.go when more than one Docker daemon host was supplied. The docker CLI can only connect to a single daemon per invocation, so when the accumulated hosts slice has length greater than one it refuses to guess which endpoint to use and fails fast.","triggerScenarios":"Passing the -H/--host flag more than once on the docker command line (e.g. `docker -H tcp://a:2375 -H tcp://b:2375 ps`), or combining a -H flag with a hosts list injected programmatically via CLI options so that len(hosts) > 1 when getServerHost runs during DockerCli initialization.","commonSituations":"Shell aliases or wrapper scripts that already embed a -H flag while the user adds another one; CI pipelines that both export DOCKER_HOST and pass -H through a templated command (only duplicate flags trigger it — DOCKER_HOST alone is used just when no -H is given); copy-pasted commands intended for docker swarm-era multi-host tooling.","solutions":["Remove the duplicate -H/--host flag and keep exactly one daemon endpoint per docker invocation.","Check shell aliases, DOCKER_* wrapper scripts, and Makefiles for a hidden -H flag before adding your own (`type docker`, `alias`).","If you need to target multiple daemons, use docker contexts (`docker context use <name>`) or run separate invocations instead of stacking -H flags."],"exampleFix":"# before\ndocker -H tcp://host-a:2375 -H tcp://host-b:2375 ps\n# after\ndocker -H tcp://host-a:2375 ps\ndocker -H tcp://host-b:2375 ps","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","cli-flags","daemon-connection"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}