work around docker sdk weirdness#1198
Merged
Merged
Conversation
docker.from_env() does not consult Docker contexts -- it only reads DOCKER_HOST and falls back to /var/run/docker.sock. On macOS with Docker Desktop, the CLI works via the "desktop-linux" context pointing to ~/.docker/run/docker.sock, but the Python SDK fails if /var/run/docker.sock is missing or broken. Now _docker_client reads the active Docker context first (when DOCKER_HOST is not set), matching Docker CLI behavior. Closes #1167 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…nistic tests Extract the context-aware Docker client creation into a public create_docker_client() function and use it in conftest.py and testing.py (previously using docker.from_env() directly). Replace the environment-dependent test with deterministic tests using a fake Docker config directory via DOCKER_CONFIG env var. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Problem: The except clause caught (OSError, json.JSONDecodeError) but the Docker SDK's Context._load_meta() raises a bare Exception when context metadata is corrupted. A corrupted non-default context meta file would propagate an unhandled exception instead of gracefully falling back to docker.from_env(). Fix: Catch Exception broadly since the Docker SDK uses bare Exception for corrupted context metadata. Added a test for this case and bumped the broad-exception-catch ratchet count from 1 to 2. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Problem: write_fake_docker_context is a non-fixture helper function placed in conftest.py and explicitly imported in test files. Per project conventions, conftest.py should only contain fixtures and hooks. Fix: Moved the helper to testing.py (where non-fixture test utilities belong) and updated the import in instance_test.py. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
# Conflicts: # libs/mngr/imbue/mngr/providers/docker/instance.py # libs/mngr/imbue/mngr/providers/docker/instance_test.py
evgunter
commented
Apr 9, 2026
|
|
||
| def test_prevent_broad_exception_catch() -> None: | ||
| rc.check_broad_exception_catch(_DIR, snapshot(1)) | ||
| rc.check_broad_exception_catch(_DIR, snapshot(2)) |
Contributor
Author
There was a problem hiding this comment.
docker sdk raises bare Exception -_-
The docs regeneration hook produced incorrect output because the vultr plugin is not installed in this worktree. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
gross, but sure, LGTM |
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
Closes #1167
mngr listwas failing with "Cannot list Docker hosts (Docker daemon unavailable?)" on macOS Docker Desktop even thoughdocker psworked fine.docker.from_env()does not read Docker contexts. It only checksDOCKER_HOSTenv var and falls back to/var/run/docker.sock. On macOS Docker Desktop, the active context is typicallydesktop-linuxpointing to~/.docker/run/docker.sock, which is what the Docker CLI uses -- but the SDK ignores this entirely.What changed
_get_docker_context_host()which reads the active Docker context viadocker.context.ContextAPI(already available in the SDK, just not used byfrom_env()).create_docker_client()as the public entry point with the correct resolution order: explicit config >DOCKER_HOSTenv > Docker context > platform default.docker.from_env()callsites (production and test infrastructure) to usecreate_docker_client().DOCKER_CONFIGenv var.Docker SDK details
The SDK's
Context._load_meta()raises bareException(not a subclass) for corrupted context metadata, which required a broadexcept Exceptionwith a ratchet bump. The relevant SDK code:Test plan
create_docker_client()resolves to the correct socket on a macOS Docker Desktop machineGenerated with Claude Code