{"record":{"id":"d1c836994f04d2e6","repo":"docker/cli","slug":"default-context-cannot-be-created-nor-updated","errorCode":null,"errorMessage":"default context cannot be created nor updated","messagePattern":"default context cannot be created nor updated","errorType":"validation","errorClass":"invalidParameterErr","httpStatus":null,"severity":"error","filePath":"cli/command/defaultcontextstore.go","lineNumber":121,"sourceCode":"}\n\n// List implements store.Store's List\nfunc (s *ContextStoreWithDefault) List() ([]store.Metadata, error) {\n\tcontextList, err := s.Store.List()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefaultContext, err := s.Resolver()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn append(contextList, defaultContext.Meta), nil\n}\n\n// CreateOrUpdate is not allowed for the default context and fails\nfunc (s *ContextStoreWithDefault) CreateOrUpdate(meta store.Metadata) error {\n\tif meta.Name == DefaultContextName {\n\t\treturn invalidParameter(errors.New(\"default context cannot be created nor updated\"))\n\t}\n\treturn s.Store.CreateOrUpdate(meta)\n}\n\n// Remove is not allowed for the default context and fails\nfunc (s *ContextStoreWithDefault) Remove(name string) error {\n\tif name == DefaultContextName {\n\t\treturn invalidParameter(errors.New(\"default context cannot be removed\"))\n\t}\n\treturn s.Store.Remove(name)\n}\n\n// GetMetadata implements store.Store's GetMetadata\nfunc (s *ContextStoreWithDefault) GetMetadata(name string) (store.Metadata, error) {\n\tif name == DefaultContextName {\n\t\tdefaultContext, err := s.Resolver()\n\t\tif err != nil {\n\t\t\treturn store.Metadata{}, err","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/defaultcontextstore.go#L103-L139","documentation":"ContextStoreWithDefault.CreateOrUpdate() guards the reserved name \"default\": because the default context is resolved on the fly from env/config rather than persisted, the store rejects any attempt to write metadata under that name, returning an invalidParameter error.","triggerScenarios":"Programmatically calling store.CreateOrUpdate(store.Metadata{Name: \"default\", ...}) on a ContextStoreWithDefault, or `docker context create default` which routes here.","commonSituations":"Migration tooling that round-trips all contexts through CreateOrUpdate; scripts that reuse \"default\" as a custom name expecting to override it.","solutions":["Choose a non-reserved name for the context you want to persist","To alter the default's connection, set DOCKER_HOST / TLS env vars instead","Filter out \"default\" before bulk-writing contexts"],"exampleFix":"// before\nstore.CreateOrUpdate(store.Metadata{Name: \"default\", ...})\n// after\nstore.CreateOrUpdate(store.Metadata{Name: \"myctx\", ...})","handlingStrategy":"validation","validationCode":"if meta.Name == command.DefaultContextName {\n    return fmt.Errorf(\"cannot create or update the reserved %q context; use env vars to configure it\", command.DefaultContextName)\n}\nreturn store.CreateOrUpdate(meta)","typeGuard":"func isReservedContextName(name string) bool { return name == command.DefaultContextName }","tryCatchPattern":null,"preventionTips":["Never reuse \"default\" as a custom context name","Filter reserved names before bulk-writing contexts programmatically","Configure the default context via DOCKER_HOST and DOCKER_* TLS env vars"],"tags":["context","store","cli"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}