wagoodman/dive · error
could not determine docker host: %v
Error message
could not determine docker host: %v
What it means
Returned by engineResolver.fetchArchive (dive/image/docker/engine_resolver.go:75) wrapping a failure of determineDockerHost(). That helper reads DOCKER_HOST, then DOCKER_CONTEXT, then ~/.docker/config.json (cliconfig.Load), then resolves the named context from the context store (~/.docker/contexts). Any failure loading the config file or fetching context metadata surfaces here as 'could not determine docker host: %v'.
Source
Thrown at dive/image/docker/engine_resolver.go:75
reader, err := r.fetchArchive(ctx, id)
if err != nil {
return err
}
if err := ExtractFromImage(io.NopCloser(reader), l, p); err == nil {
return nil
}
return fmt.Errorf("unable to extract from image '%s': %+v", id, err)
}
func (r *engineResolver) fetchArchive(ctx context.Context, id string) (io.ReadCloser, error) {
var err error
var dockerClient *client.Client
host, err := determineDockerHost()
if err != nil {
return nil, fmt.Errorf("could not determine docker host: %v", err)
}
clientOpts := []client.Opt{client.FromEnv}
clientOpts = append(clientOpts, client.WithHost(host))
switch strings.Split(host, ":")[0] {
case "ssh":
helper, err := connhelper.GetConnectionHelper(host)
if err != nil {
return nil, fmt.Errorf("failed to get docker connection helper: %w", err)
}
clientOpts = append(clientOpts, func(c *client.Client) error {
httpClient := &http.Client{
Transport: &http.Transport{
DialContext: helper.Dialer,
},
}
return client.WithHTTPClient(httpClient)(c)
})View on GitHub (pinned to d6c691947f)
Solutions
- Validate the config: docker context ls and docker info - if the docker CLI itself errors, fix that first
- Check ~/.docker/config.json parses (jq . ~/.docker/config.json) and has sane permissions
- Remove or recreate the stale context: docker context rm <name> && docker context create ...; or docker context use default
- Bypass context resolution for the dive run: DOCKER_HOST=unix:///var/run/docker.sock dive docker://<image>
Example fix
# before: stale context referenced in config $ dive docker://alpine Error: could not determine docker host: ... # after: pin the host explicitly for this run $ DOCKER_HOST=unix:///var/run/docker.sock dive docker://alpine
Defensive patterns
Strategy: validation
Validate before calling
// pre-flight docker environment check
func dockerEnvOK() error {
if os.Getenv("DOCKER_HOST") != "" {
return nil // explicit host wins; no context resolution needed
}
if b, err := os.ReadFile(filepath.Join(os.Getenv("HOME"), ".docker", "config.json")); err == nil {
if !json.Valid(b) {
return fmt.Errorf("~/.docker/config.json is not valid JSON")
}
}
return nil
} Try / catch
reader, err := resolver.Fetch(ctx, id)
if err != nil && strings.Contains(err.Error(), "could not determine docker host") {
// recover by pinning the host explicitly for this process
os.Setenv("DOCKER_HOST", "unix:///var/run/docker.sock")
reader, err = resolver.Fetch(ctx, id)
}
if err != nil {
return err
} Prevention
- Set DOCKER_HOST explicitly in CI to bypass context resolution
- Keep ~/.docker/config.json valid (verify with jq) and prune stale contexts (docker context ls)
- After removing Docker Desktop or contexts, run 'docker context use default'
When it happens
Trigger: Malformed ~/.docker/config.json (bad JSON, wrong perms) that cliconfig.Load rejects; DOCKER_CONTEXT (or config's currentContext) naming a context whose metadata cannot be read - deleted context dir, partial write, version-incompatible context store.
Common situations: Manually edited or tool-generated docker config files; contexts created by Docker Desktop removed out-of-band; home-dir sync/restore that half-copied ~/.docker/contexts; switching between Docker Desktop and plain engine installs.
Related errors
- cannot determine image provider for build: %w
- cannot determine image provider to fetch from: %w
- cannot find docker client executable
- failed to get docker connection helper: %w
- evaluation failed
AI-assisted analysis of wagoodman/dive@d6c691947f (2026-08-15).
Data as JSON: /api/errors/bd32b664e7ed9d4a.
Report an issue: GitHub.