Skip to content

Resolve default daemon endpoint like the docker CLI (DOCKER_HOST + contexts) - #710

Closed
ebriney wants to merge 4 commits into
dotnet:masterfrom
ebriney:feature/docker-cli-style-defaults
Closed

Resolve default daemon endpoint like the docker CLI (DOCKER_HOST + contexts)#710
ebriney wants to merge 4 commits into
dotnet:masterfrom
ebriney:feature/docker-cli-style-defaults

Conversation

@ebriney

@ebriney ebriney commented May 29, 2026

Copy link
Copy Markdown

@

What

Makes the parameterless DockerClientConfiguration() resolve the Docker daemon endpoint the same way the docker CLI does, instead of jumping straight to the platform default socket.

Resolution order (new DockerContextResolver):

  1. DOCKER_HOST environment variable (DOCKER_TLS_VERIFY upgrades tcp:// to https://)
  2. Docker contextDOCKER_CONTEXT env var, or currentContext from ~/.docker/config.json, looked up under ~/.docker/contexts/meta/<sha256(name)>/meta.json
  3. Platform default socketunix:/var/run/docker.sock on Linux/macOS, npipe://./pipe/docker_engine on Windows

DOCKER_CONFIG is honored to override the config directory. Paths derive from the user profile, so the same code works on Linux, macOS, and Windows.

Also

  • DockerClientConfiguration.FromContext(name, ...) for targeting a named context explicitly. It composes with the existing credential types (CertificateCredentials, BasicAuthCredentials, ...) just like the regular constructor.
  • ssh:// endpoints are now rejected with a clear NotSupportedException that points users at an SSH tunnel + DOCKER_HOST, rather than the generic "Unknown URL scheme" error.
  • README Usage section split into three subsections: default client (env → context → platform default), an explicit endpoint, and FromContext.

Tests

Adds DockerContextResolverTests covering DOCKER_HOST, TLS upgrade, context lookup, DOCKER_CONFIG override, and platform defaults.

Compatibility

The parameterless constructor previously always returned the platform default socket. Callers in environments with DOCKER_HOST/contexts set will now connect where the docker CLI connects. Explicit-endpoint constructors are unchanged.

🤖 Generated with Claude Code
@

ebriney and others added 4 commits May 29, 2026 11:48
Resolves the Docker daemon endpoint the same way the docker CLI does,
in this order:

  1. DOCKER_HOST environment variable (DOCKER_TLS_VERIFY upgrades
     tcp:// to https://)
  2. DOCKER_CONTEXT env var, or currentContext from
     ~/.docker/config.json, looked up under
     ~/.docker/contexts/meta/<sha256(name)>/meta.json
  3. Platform default socket (unix:/var/run/docker.sock on
     Linux/macOS, npipe://./pipe/docker_engine on Windows)

DOCKER_CONFIG is honored to override the config directory. Paths are
derived from the user profile so the same code works on Linux, macOS,
and Windows.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The parameterless DockerClientConfiguration() constructor now uses
DockerContextResolver instead of jumping straight to the platform
default socket, so it transparently honors DOCKER_HOST and the active
Docker context just like the docker CLI.

Add DockerClientConfiguration.FromContext(name, ...) for targeting a
named context explicitly. It composes with existing credential types
(CertificateCredentials, BasicAuthCredentials, ...) the same way as
the regular constructor.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
SSH-based Docker contexts can now be resolved by DockerContextResolver,
but ssh:// is not a transport this client implements. Surface that as
a NotSupportedException with guidance to use an SSH tunnel and point
DOCKER_HOST (or a context) at the forwarded socket, instead of the
generic "Unknown URL scheme" error.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Split the Usage section into three subsections: the default client
(env -> context -> platform default), an explicit endpoint, and
DockerClientConfiguration.FromContext for targeting a named context.
Adds a note that ssh:// endpoints are not supported.

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

ebriney commented May 29, 2026

Copy link
Copy Markdown
Author

@dotnet-policy-service agree company="Docker"

@HofmeisterAn

Copy link
Copy Markdown
Contributor

@ebriney This repo is inactive, we forked it some time ago and maintaining it.

We introduced a new DockerClientBuilder, and I think it would be great if it could take the environment into account automatically. We also use these variables in our tests.

Happy to review the PR if you're interested in contributing.

@ebriney

ebriney commented May 29, 2026

Copy link
Copy Markdown
Author

@HofmeisterAn, thanks. So, do you want me to do a PR in https://github.com/testcontainers/Docker.DotNet?

@HofmeisterAn

HofmeisterAn commented May 29, 2026

Copy link
Copy Markdown
Contributor

@HofmeisterAn, thanks. So, do you want me to do a PR in https://github.com/testcontainers/Docker.DotNet?

@ebriney This repo (https://github.com/dotnet/Docker.DotNet) has been inactive for about two years. No PRs have been merged, and the last release was in May 2023. I doubt this change will make it into main.

If you want these changes in the maintained and up-to-date version of Docker.DotNet, yes. But you'll need to adapt them to the newer client implementation since quite a few things have changed.

@ebriney

ebriney commented Jun 1, 2026

Copy link
Copy Markdown
Author

@HofmeisterAn : opened and tested testcontainers#108

@ebriney ebriney closed this Jun 1, 2026
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