docker/cli · error · invalidParameterErr

default context cannot be removed

Error message

default context cannot be removed

What it means

ContextStoreWithDefault.Remove() is the store-level mirror of the remove-command guard: it refuses to Remove("default") because the default context is not a deletable stored entity. Any code path that reaches the store with the reserved name gets an invalidParameter error here.

Solutions

  1. Skip the "default" name before calling Remove
  2. Use DOCKER_CONTEXT to switch away rather than deleting default
  3. Guard callers against the reserved DefaultContextName constant

Example fix

// before
store.Remove("default")
// after
if name != command.DefaultContextName { store.Remove(name) }
Defensive patterns

Strategy: validation

Validate before calling

if name == command.DefaultContextName {
    return nil // no-op: default context is not deletable
}
return store.Remove(name)

Type guard

func isReservedContextName(name string) bool { return name == command.DefaultContextName }

Prevention

When it happens

Trigger: Calling ContextStoreWithDefault.Remove("default") directly, or a higher-level command that did not pre-filter the name.

Common situations: A generic context-management library enumerating and deleting contexts; the rm command's guard was bypassed (e.g. an older client path).

Related errors


AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07). Data as JSON: /api/errors/5aa199d6da0ede5b. Report an issue: GitHub.

Appendix: 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 4f84911bfe)