{"record":{"id":"954497ec030f8154","repo":"docker/cli","slug":"cannot-use-docker-flag-when-from-is-set","errorCode":null,"errorMessage":"cannot use --docker flag when --from is set","messagePattern":"cannot use --docker flag when --from is set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/context/create.go","lineNumber":134,"sourceCode":"\treturn contextStore.ResetTLSMaterial(name, &contextTLSData)\n}\n\nfunc checkContextNameForCreation(s store.Reader, name string) error {\n\tif err := store.ValidateContextName(name); err != nil {\n\t\treturn err\n\t}\n\tif _, err := s.GetMetadata(name); !errdefs.IsNotFound(err) {\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error while getting existing contexts: %w\", err)\n\t\t}\n\t\treturn fmt.Errorf(\"context %q already exists\", name)\n\t}\n\treturn nil\n}\n\nfunc createFromExistingContext(s store.ReaderWriter, name string, fromContextName string, opts createOptions) error {\n\tif len(opts.endpoint) != 0 {\n\t\treturn errors.New(\"cannot use --docker flag when --from is set\")\n\t}\n\treader := store.Export(fromContextName, &descriptionDecorator{\n\t\tReader:      s,\n\t\tdescription: opts.description,\n\t})\n\tdefer reader.Close()\n\treturn store.Import(name, s, reader)\n}\n\ntype descriptionDecorator struct {\n\tstore.Reader\n\tdescription string\n}\n\nfunc (d *descriptionDecorator) GetMetadata(name string) (store.Metadata, error) {\n\tc, err := d.Reader.GetMetadata(name)\n\tif err != nil {\n\t\treturn c, err","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/context/create.go#L116-L152","documentation":"Returned by createFromExistingContext when --from is set AND --docker is also provided. When cloning from another context the endpoint is taken wholesale from the source, so specifying --docker would conflict; the CLI forbids the combination at create.go:132-135. The user must choose to clone OR to define a fresh endpoint.","triggerScenarios":"`docker context create new --from default --docker host=tcp://host:2376`. opts.from != \"\" and len(opts.endpoint) != 0.","commonSituations":"Trying to clone a context while overriding its host in one step (not supported). Scripts templating both flags. Confusion about whether --from copies endpoints.","solutions":["To clone, drop --docker: `docker context create new --from default`.","To set a custom endpoint, drop --from and use --docker: `docker context create new --docker host=...`.","If you need to clone then modify, clone first and use `docker context update` (or remove + recreate)."],"exampleFix":"// before\ndocker context create new --from default --docker host=tcp://host:2376\n\n// after\ndocker context create new --from default","handlingStrategy":"validation","validationCode":"func validateContextCreate(from string, endpoint map[string]string) error {\n    if from != \"\" && len(endpoint) != 0 {\n        return errors.New(\"cannot use --docker flag when --from is set\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat --from and --docker as mutually exclusive in wrapper tooling.","To clone-then-modify, clone first then update separately.","Document the either/or rule in context management scripts."],"tags":["context","cli-options","conflicting-flags","endpoint"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}