{"id":"5aa199d6da0ede5b","repo":"docker/cli","slug":"default-context-cannot-be-removed","errorCode":null,"errorMessage":"default context cannot be removed","messagePattern":"default context cannot be removed","errorType":"validation","errorClass":"invalidParameter","httpStatus":null,"severity":"error","filePath":"cli/command/defaultcontextstore.go","lineNumber":129,"sourceCode":"\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\n\t\t}\n\t\treturn defaultContext.Meta, nil\n\t}\n\treturn s.Store.GetMetadata(name)\n}\n\n// ResetTLSMaterial is not implemented for default context and fails\nfunc (s *ContextStoreWithDefault) ResetTLSMaterial(name string, data *store.ContextTLSData) error {","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/defaultcontextstore.go#L111-L147","documentation":"ContextStoreWithDefault.Remove rejects any attempt to remove the context named 'default'. The default context is not stored on disk like user-created contexts; it is synthesized at runtime by a Resolver from the CLI's current config (DOCKER_HOST, TLS flags, config file), so there is nothing to delete and removing it would break the CLI's baseline connection state. The error is wrapped as an invalid-parameter (client-side) error.","triggerScenarios":"Running `docker context rm default` (or any code path calling store.Remove(\"default\") on a ContextStoreWithDefault), including `docker context rm` with a list of names that happens to include 'default'.","commonSituations":"Users trying to 'reset' their Docker CLI by deleting all contexts with a loop or `docker context rm $(docker context ls -q)`, which includes 'default'; scripts cleaning up test contexts without filtering out the default name; users confusing `docker context rm` with `docker context use` when trying to switch away from a broken context.","solutions":["Exclude 'default' from removal: `docker context ls -q | grep -v '^default$' | xargs -r docker context rm`.","If the goal is to change what 'default' points at, set DOCKER_HOST/DOCKER_TLS_VERIFY or edit ~/.docker/config.json instead — the default context reflects those settings.","If the goal is to stop using a custom context, run `docker context use default` and remove the custom context instead."],"exampleFix":"# before\ndocker context rm $(docker context ls -q)\n# after\ndocker context rm $(docker context ls -q | grep -v '^default$')","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","context-store","invalid-parameter"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}