Bollard follows the same context-resolution rules as the Docker CLI. When you call a context-aware connection method, Bollard inspects environment variables and your Docker config file to discover which daemon endpoint to connect to — no manual configuration required if your CLI is already pointed at the right daemon.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/fussybeaver/bollard/llms.txt
Use this file to discover all available pages before exploring further.
Resolution Precedence
Bollard evaluates the following sources in order, using the first one that is set and non-empty:DOCKER_HOST environment variable
If
DOCKER_HOST is set to a non-empty value, it is used directly as the daemon endpoint, bypassing all context machinery.DOCKER_CONTEXT environment variable
If
DOCKER_CONTEXT names a context (e.g. desktop-linux), Bollard looks up that context under the Docker config directory and returns its Endpoints.docker.Host value.currentContext in ~/.docker/config.json
If
DOCKER_CONTEXT is not set, Bollard reads the currentContext field from ~/.docker/config.json (or $DOCKER_CONFIG/config.json if the DOCKER_CONFIG variable is set) and performs the same context lookup.DOCKER_HOST is a transport override, not a context selector. Methods like Docker::connect_with_current_context() intentionally ignore DOCKER_HOST so that they respect exactly the context-selection inputs (DOCKER_CONTEXT and config.json). Use Docker::connect_with_defaults() if you want DOCKER_HOST to win over everything else.Context Storage
Named contexts are stored as JSON files on disk. Bollard searches for them at:DOCKER_CONFIG is not set, the directory defaults to ~/.docker (Linux/macOS) or %USERPROFILE%\.docker (Windows).
Each meta.json file contains the context name and its endpoint:
meta/ subdirectories and matches by the Name field — it does not recompute the SHA-256 directory hash used by the Docker CLI.
The context name
"default" (or an empty string) is special — it always resolves to the platform default socket rather than looking up a stored context on disk.API Methods
Docker::connect_with_defaults()
Fully context-aware connection that respects the complete resolution precedence: DOCKER_HOST → DOCKER_CONTEXT → currentContext in config.json → platform default.
Docker::connect_with_current_context()
Follows the Docker CLI’s context-only selection: checks DOCKER_CONTEXT, then currentContext in config.json, then falls back to the platform default. DOCKER_HOST is not consulted.
Docker::connect_with_context(name)
Connects to a specific named context, ignoring all environment variables. Pass "default" or an empty string to connect to the platform default.
Code Examples
Environment Variables Summary
| Variable | Effect |
|---|---|
DOCKER_HOST | Overrides the daemon endpoint entirely (consulted by connect_with_defaults only) |
DOCKER_CONTEXT | Selects a named context to look up in the config directory |
DOCKER_CONFIG | Override for the Docker config directory (default: ~/.docker) |
