docker/cli · error
context
Error message
context %q: %w
What it means
Top-level wrapper returned by ContextStore.GetMetadata() for any failure looking up a context by name. It wraps the underlying getByID error — most often the not-found error (504) but also any parse or I/O failure — and includes the context name for diagnostics.
Solutions
- Run `docker context ls` to confirm the exact context name exists.
- If the inner error is 'context not found', create or switch to an existing context (`docker context use default`).
- If the inner error is a parse/IO error, inspect meta.json on disk or recreate the context.
Defensive patterns
Strategy: try-catch
Try / catch
meta, err := store.GetMetadata(name)
if err != nil {
// GetMetadata wraps the underlying cause with the context name.
if errors.Is(err, errdefs.ErrNotFound) {
// missing context — create or fall back
}
return err
} Prevention
- List existing contexts before assuming a name exists.
- Unwrap the error (errors.Is) to distinguish not-found from corruption rather than string-matching.
- Validate the name with ValidateContextName before lookup to rule out typos/format errors.
When it happens
Trigger: Calling store.GetMetadata(name) where name has no directory (wraps not-found), or where the context's meta.json is corrupt/unreadable (wraps a parse/IO error).
Common situations: Typo in context name; referencing a context after `docker context rm`; corrupted context directory; shell completion or scripts probing arbitrary names.
Related errors
- failed to retrieve context tls info
- endpoint is not of type EndpointMeta
- context not found
- conflicting options: cannot specify both --host and…
- context metadata is not a valid DockerContext
AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07).
Data as JSON: /api/errors/ac472f636720f874.
Report an issue: GitHub.
Appendix: source
Thrown at cli/context/store/metadatastore.go:66
}
if getter == nil {
var res map[string]any
if err := json.Unmarshal(payload, &res); err != nil {
return nil, err
}
return res, nil
}
typed := getter()
if err := json.Unmarshal(payload, typed); err != nil {
return nil, err
}
return reflect.ValueOf(typed).Elem().Interface(), nil
}
func (s *metadataStore) get(name string) (Metadata, error) {
m, err := s.getByID(contextdirOf(name))
if err != nil {
return m, fmt.Errorf("context %q: %w", name, err)
}
return m, nil
}
func (s *metadataStore) getByID(id contextdir) (Metadata, error) {
fileName := filepath.Join(s.contextDir(id), metaFile)
bytes, err := os.ReadFile(fileName)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return Metadata{}, notFound(fmt.Errorf("context not found: %w", err))
}
return Metadata{}, err
}
var untyped untypedContextMetadata
r := Metadata{
Endpoints: make(map[string]any),
}
if err := json.Unmarshal(bytes, &untyped); err != nil {View on GitHub (pinned to 4f84911bfe)