docker/cli · error · invalidParameter

default context cannot be removed

Error message

default context cannot be removed

What it means

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.

Source

Thrown at cli/command/defaultcontextstore.go:129

	defaultContext, err := s.Resolver()
	if err != nil {
		return nil, err
	}
	return append(contextList, defaultContext.Meta), nil
}

// CreateOrUpdate is not allowed for the default context and fails
func (s *ContextStoreWithDefault) CreateOrUpdate(meta store.Metadata) error {
	if meta.Name == DefaultContextName {
		return invalidParameter(errors.New("default context cannot be created nor updated"))
	}
	return s.Store.CreateOrUpdate(meta)
}

// Remove is not allowed for the default context and fails
func (s *ContextStoreWithDefault) Remove(name string) error {
	if name == DefaultContextName {
		return invalidParameter(errors.New("default context cannot be removed"))
	}
	return s.Store.Remove(name)
}

// GetMetadata implements store.Store's GetMetadata
func (s *ContextStoreWithDefault) GetMetadata(name string) (store.Metadata, error) {
	if name == DefaultContextName {
		defaultContext, err := s.Resolver()
		if err != nil {
			return store.Metadata{}, err
		}
		return defaultContext.Meta, nil
	}
	return s.Store.GetMetadata(name)
}

// ResetTLSMaterial is not implemented for default context and fails
func (s *ContextStoreWithDefault) ResetTLSMaterial(name string, data *store.ContextTLSData) error {

View on GitHub (pinned to e9452d6e78)

Solutions

  1. Exclude 'default' from removal: `docker context ls -q | grep -v '^default$' | xargs -r docker context rm`.
  2. 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.
  3. If the goal is to stop using a custom context, run `docker context use default` and remove the custom context instead.

Example fix

# before
docker context rm $(docker context ls -q)
# after
docker context rm $(docker context ls -q | grep -v '^default$')

When it happens

Trigger: 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'.

Common situations: 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.

Related errors


AI-assisted analysis of docker/cli@e9452d6e78 (2026-08-01). Data as JSON: /data/errors/5aa199d6da0ede5b.json. Report an issue: GitHub.