{"id":"2199908fc49af0b2","repo":"docker/cli","slug":"conflicting-options-cannot-specify-both-host-an","errorCode":null,"errorMessage":"conflicting options: cannot specify both --host and --context","messagePattern":"conflicting options: cannot specify both --host and --context","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/cli.go","lineNumber":227,"sourceCode":"// Initialize the dockerCli runs initialization that must happen after command\n// line flags are parsed.\nfunc (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...CLIOption) error {\n\tfor _, o := range ops {\n\t\tif err := o(cli); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\tcliflags.SetLogLevel(opts.LogLevel)\n\n\tif opts.ConfigDir != \"\" {\n\t\tconfig.SetDir(opts.ConfigDir)\n\t}\n\n\tif opts.Debug {\n\t\tdebug.Enable()\n\t}\n\tif opts.Context != \"\" && len(opts.Hosts) > 0 {\n\t\treturn errors.New(\"conflicting options: cannot specify both --host and --context\")\n\t}\n\n\tif cli.contextStoreConfig == nil {\n\t\t// This path can be hit when calling Initialize on a DockerCli that's\n\t\t// not constructed through [NewDockerCli]. Using the default context\n\t\t// store without a config set will result in Endpoints from contexts\n\t\t// not being type-mapped correctly, and used as a generic \"map[string]any\",\n\t\t// instead of a [docker.EndpointMeta].\n\t\t//\n\t\t// When looking up the API endpoint (using [EndpointFromContext]), no\n\t\t// endpoint will be found, and a default, empty endpoint will be used\n\t\t// instead which in its turn, causes newAPIClientFromEndpoint to\n\t\t// be initialized with the default config instead of settings for\n\t\t// the current context (which may mean; connecting with the wrong\n\t\t// endpoint and/or TLS Config to be missing).\n\t\t//\n\t\t// [EndpointFromContext]: https://github.com/docker/cli/blob/33494921b80fd0b5a06acc3a34fa288de4bb2e6b/cli/context/docker/load.go#L139-L149\n\t\tif err := WithDefaultContextStoreConfig()(cli); err != nil {","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/cli.go#L209-L245","documentation":"Raised in DockerCli.Initialize when both a docker context (--context or DOCKER_CONTEXT) and an explicit daemon host (--host/-H or DOCKER_HOST via flags) are supplied. Both mechanisms select which daemon endpoint to talk to, so specifying both is ambiguous; the CLI refuses to guess which should win and aborts before connecting.","triggerScenarios":"docker --context mycontext --host tcp://1.2.3.4:2376 ... ; or DOCKER_CONTEXT set in the environment combined with -H on the command line (opts.Context non-empty and len(opts.Hosts) > 0 at Initialize time).","commonSituations":"Shell profiles exporting DOCKER_CONTEXT while scripts pass -H; wrapper scripts/Makefiles adding -H to a CLI where the user has 'docker context use' set plus an explicit --context flag; CI pipelines mixing context-based and host-based daemon selection.","solutions":["Drop the --host/-H flag and rely on the context: docker --context mycontext ...","Or drop --context (and unset DOCKER_CONTEXT) and use --host alone","Check for a lingering DOCKER_CONTEXT environment variable: unset DOCKER_CONTEXT","Encode the desired host as a context instead: docker context create myhost --docker host=tcp://... then use --context myhost"],"exampleFix":"# before\nDOCKER_CONTEXT=remote docker -H tcp://10.0.0.5:2376 ps\n# after\ndocker --context remote ps","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","configuration","context","docker-host","flags"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}