Documentation
¶
Overview ¶
Package dockerhost resolves the Docker Engine endpoint the same way the docker CLI does, so human reaches the engine out-of-the-box on setups that expose the socket via a docker *context* (colima, OrbStack, Rancher Desktop, Docker Desktop, Podman) rather than via DOCKER_HOST.
The Docker Go SDK's client.FromEnv only reads environment variables; it does not consult the docker CLI context store. This package bridges that gap with a single shared resolver used by every Docker client constructor in human so the two can never diverge.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UnreachableError ¶
UnreachableError builds an actionable error for a failed Docker connection. It names the active context and the attempted endpoint and gives a one-line remedy, replacing the opaque generic failure users used to see.
Types ¶
type Option ¶
type Option func(*options)
Option customizes resolution. Production callers pass none and get the real os/config-backed behavior.
type Result ¶
type Result struct {
// Host is the resolved Docker endpoint, or "" when the caller should fall
// back to the SDK's env/platform default.
Host string
// Context is the active docker context name ("default" when none).
Context string
// Source explains where Host came from: "env" (DOCKER_HOST set), "context"
// (resolved from the context store), or "default" (platform fallback).
Source string
}
Result describes the outcome of context resolution. Host is the endpoint to hand to the Docker SDK (empty means "use the SDK's env/platform default"). Context and Source explain *why* that host was chosen so callers can build an actionable error when the engine turns out to be unreachable.
func Resolve ¶
Resolve mirrors the docker CLI's context precedence:
- DOCKER_HOST set => explicit env wins; return Host="" so the SDK's FromEnv handles it (Source "env").
- otherwise context name = DOCKER_CONTEXT, else config.json currentContext, else "default".
- context == "default" => Host="" so the SDK uses the platform default socket/pipe (Source "default").
- otherwise read Endpoints.docker.Host from the context store and return it (Source "context").
Any failure to read the store (missing/malformed config.json, missing meta.json, missing docker endpoint) degrades gracefully to the platform default rather than blocking startup.