{"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/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/context/create.go#L116-L152","documentation":"When `docker context create` is given --from, it copies (store.Export/Import) an existing context wholesale, including its docker endpoint. Supplying --docker at the same time is contradictory — the copied endpoint and the explicit one would conflict — so createFromExistingContext rejects the combination when opts.endpoint is non-empty.","triggerScenarios":"`docker context create newctx --from oldctx --docker \"host=tcp://...\"` — any invocation where both --from and one or more --docker key=value pairs are set, hitting cli/command/context/create.go:133.","commonSituations":"Trying to 'clone a context but change its host' in one command; templated scripts that always append --docker while a user adds --from; misunderstanding --from as only copying description/metadata rather than the full endpoint set.","solutions":["To clone with a different endpoint, drop --from and specify the endpoint fully: `docker context create newctx --docker \"host=ssh://newhost\"`.","To clone as-is, drop --docker: `docker context create newctx --from oldctx`.","To change an existing/cloned context's endpoint afterwards, use `docker context update newctx --docker \"host=...\"`."],"exampleFix":"# before\ndocker context create staging --from prod --docker \"host=ssh://staging-host\"\n# after\ndocker context create staging --from prod\ndocker context update staging --docker \"host=ssh://staging-host\"","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","context","flags","mutually-exclusive"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}