Skip to content

Add docker CLI contexts support to NewClientFromEnv - #1186

Open
ebriney wants to merge 2 commits into
fsouza:mainfrom
ebriney:docker-contexts-support
Open

ebriney wants to merge 2 commits into
fsouza:mainfrom
ebriney:docker-contexts-support

Conversation

@ebriney

@ebriney ebriney commented Jun 4, 2026

Copy link
Copy Markdown

Summary

  • New NewContextClient(name) / NewVersionedContextClient(name, apiVersion) build a client from a named docker CLI context by reading $DOCKER_CONFIG/contexts/meta/<sha256(name)>/meta.json and the optional TLS bundle under contexts/tls/<id>/docker/. The reserved name default (or "") resolves to the platform default host.
  • NewClientFromEnv / NewVersionedClientFromEnv now match the docker CLI's resolution order: DOCKER_HOST keeps full precedence; when it's unset the client falls back to DOCKER_CONTEXT, then the currentContext field of config.json, then the default socket.
  • ssh:// context endpoints are rejected with a clear error since this library has no SSH dialer.

Test plan

  • go test ./... (unit tests, Linux/macOS)
  • Manual smoke test on Windows
  • NewClientFromEnv with DOCKER_HOST set still hits that host (existing tests cover this)
  • NewClientFromEnv with a docker context use <name> selecting a tcp:// context picks up that host
  • NewContextClient("default") resolves to the platform default host without touching disk
  • NewContextClient on a missing context returns a clear "not found" error
  • NewContextClient on an ssh:// context returns an explanatory error

🤖 Generated with Claude Code

ebriney and others added 2 commits June 4, 2026 12:32
Read $DOCKER_CONFIG/contexts/meta/<sha256(name)>/meta.json and the
optional TLS bundle under contexts/tls/<id>/docker/ to build a Client
from a named docker CLI context. The reserved name "default" resolves
to the platform default host. ssh:// endpoints are rejected explicitly
since this library has no SSH dialer.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
When DOCKER_HOST is unset, look up the active context (DOCKER_CONTEXT,
falling back to currentContext in config.json) and build the client
from it. DOCKER_HOST keeps full precedence over contexts, matching the
docker CLI's resolution order.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@fsouza

fsouza commented Aug 22, 2026

Copy link
Copy Markdown
Owner

Sorry I lost track of this, can you rebase so CI can run again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants