[DKP-2535] Honour context if present for default client, add contexts support#3401
Open
ebriney wants to merge 2 commits into
Open
[DKP-2535] Honour context if present for default client, add contexts support#3401ebriney wants to merge 2 commits into
ebriney wants to merge 2 commits into
Conversation
Resolves a Docker CLI context (honouring DOCKER_CONTEXT, then currentContext in ~/.docker/config.json, then the built-in default context) and returns base_url / tls kwargs ready to be passed to APIClient. Used by the client to talk to Docker Desktop out of the box. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Emmanuel Briney <emmanuel.briney@docker.com>
DockerClient.from_env() now falls back to the current Docker CLI context when DOCKER_HOST is unset, so docker.from_env() targets Docker Desktop (or any other configured context) out of the box. DOCKER_HOST still wins when set, matching the CLI's precedence. Callers can opt out with use_context=False. Also adds DockerClient.from_context(name=None) (exposed as docker.from_context) for explicit context selection. Existing pool-size unit tests are pinned with use_context=False so they stay deterministic regardless of the developer's current context. New tests cover: current-context fallback, DOCKER_HOST precedence, opt-out, named-context selection, unknown-context safety, and default-context resolution. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Emmanuel Briney <emmanuel.briney@docker.com>
39699ff to
37e5945
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of changes:
for APIClient.
All 14 new/adjusted tests pass; the remaining pytest tests/unit/ failures are pre-existing on main (verified by stashing and re-running). The behavior matches the Docker CLI: DOCKER_HOST wins, then DOCKER_CONTEXT, then currentContext, then default.