Resolve default daemon endpoint like the docker CLI (DOCKER_HOST + contexts) - #710
Resolve default daemon endpoint like the docker CLI (DOCKER_HOST + contexts)#710ebriney wants to merge 4 commits into
Conversation
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>
|
@dotnet-policy-service agree company="Docker" |
|
@ebriney This repo is inactive, we forked it some time ago and maintaining it. We introduced a new Happy to review the PR if you're interested in contributing. |
|
@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. |
|
@HofmeisterAn : opened and tested testcontainers#108 |
@
What
Makes the parameterless
DockerClientConfiguration()resolve the Docker daemon endpoint the same way thedockerCLI does, instead of jumping straight to the platform default socket.Resolution order (new
DockerContextResolver):DOCKER_HOSTenvironment variable (DOCKER_TLS_VERIFYupgradestcp://tohttps://)DOCKER_CONTEXTenv var, orcurrentContextfrom~/.docker/config.json, looked up under~/.docker/contexts/meta/<sha256(name)>/meta.jsonunix:/var/run/docker.sockon Linux/macOS,npipe://./pipe/docker_engineon WindowsDOCKER_CONFIGis 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 clearNotSupportedExceptionthat points users at an SSH tunnel +DOCKER_HOST, rather than the generic "Unknown URL scheme" error.FromContext.Tests
Adds
DockerContextResolverTestscoveringDOCKER_HOST, TLS upgrade, context lookup,DOCKER_CONFIGoverride, 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 thedockerCLI connects. Explicit-endpoint constructors are unchanged.🤖 Generated with Claude Code
@