docker/cli · error
no context store initialized
Error message
no context store initialized
What it means
resolveDockerEndpoint looks up the daemon endpoint (host URL, TLS material) for a named context from a context store.Reader. If the store passed in is nil there is nowhere to read context metadata from, so it fails fast with this error instead of dereferencing nil. In the stock CLI a store is always constructed; a nil store indicates DockerCli was used before Initialize, or embedding code skipped store setup.
Source
Thrown at cli/command/cli.go:324
return nil, err
}
if len(configFile.HTTPHeaders) > 0 {
opts = append(opts, client.WithHTTPHeaders(configFile.HTTPHeaders))
}
withCustomHeaders, err := withCustomHeadersFromEnv()
if err != nil {
return nil, err
}
if withCustomHeaders != nil {
opts = append(opts, withCustomHeaders)
}
opts = append(opts, extraOpts...)
return client.New(opts...)
}
func resolveDockerEndpoint(s store.Reader, contextName string) (docker.Endpoint, error) {
if s == nil {
return docker.Endpoint{}, errors.New("no context store initialized")
}
ctxMeta, err := s.GetMetadata(contextName)
if err != nil {
return docker.Endpoint{}, err
}
epMeta, err := docker.EndpointFromContext(ctxMeta)
if err != nil {
return docker.Endpoint{}, err
}
return docker.WithTLSData(s, contextName, epMeta)
}
// Resolve the Docker endpoint for the default context (based on config, env vars and CLI flags)
func resolveDefaultDockerEndpoint(opts *cliflags.ClientOptions) (docker.Endpoint, error) {
// defaultToTLS determines whether we should use a TLS host as default
// if nothing was configured by the user.
defaultToTLS := opts.TLSOptions != nil
host, err := getServerHost(opts.Hosts, defaultToTLS)View on GitHub (pinned to e9452d6e78)
Solutions
- Call DockerCli.Initialize(opts) (or construct via command.NewDockerCli) before any operation that resolves contexts or creates API clients
- In embedding code, build a store explicitly: store.New(config.ContextStoreDir(), command.DefaultContextStoreConfig()) and pass it to endpoint resolution
- In tests, inject a ContextStoreWithDefault or a fake store.Reader instead of nil
Example fix
// before
cli := &command.DockerCli{}
ep, err := resolveDockerEndpoint(nil, "default")
// after
cli, _ := command.NewDockerCli()
_ = cli.Initialize(cliflags.NewClientOptions())
// endpoint resolution now uses cli's initialized context store When it happens
Trigger: Calling code paths that reach resolveDockerEndpoint (e.g. resolving a context's endpoint for client creation) with a nil store.Reader — typically a DockerCli constructed manually without NewDockerCli/Initialize, or a unit test invoking endpoint resolution before wiring a context store.
Common situations: Third-party Go programs embedding docker/cli's command package and calling client-resolution helpers before cli.Initialize(); custom builds where contextStore initialization was refactored out; test code constructing DockerCli structs directly.
Related errors
- default context cannot be removed
- default context cannot be edited
- failed to parse hook template
- unexpected hook response type:
- plugin candidate path cannot be empty
AI-assisted analysis of docker/cli@e9452d6e78 (2026-08-01).
Data as JSON: /data/errors/a4bd0f3c155a780c.json.
Report an issue: GitHub.