dockerhost

package
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 6 Imported by: 0

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

func UnreachableError(cause error, r Result) error

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

func Resolve(opts ...Option) Result

Resolve mirrors the docker CLI's context precedence:

  1. DOCKER_HOST set => explicit env wins; return Host="" so the SDK's FromEnv handles it (Source "env").
  2. otherwise context name = DOCKER_CONTEXT, else config.json currentContext, else "default".
  3. context == "default" => Host="" so the SDK uses the platform default socket/pipe (Source "default").
  4. 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL