Repository navigation
feat: Find Docker through the current context and add --docker-timeout - #76
Merged
Merged
Conversation
nealrichardson
force-pushed
the
clean-errors
branch
from
October 23, 2026 18:39
57e37f4 to
2f9b025
Compare
nealrichardson
force-pushed
the
docker-client
branch
from
October 23, 2026 18:44
112a90c to
0e644a9
Compare
When DOCKER_HOST isn't set, use the socket of the Docker CLI's current context (DOCKER_CONTEXT, else currentContext in the Docker config), so Docker Desktop on macOS, Colima, OrbStack and similar work without setting DOCKER_HOST. Only unix:// and npipe:// context hosts are used; the default context and tcp:// or ssh:// contexts keep docker-py's from_env() behavior. The host is passed to from_env() through its environment argument instead of changing os.environ. Add --docker-timeout SECONDS (falling back to DOCKER_CLIENT_TIMEOUT) for the Docker API timeout, with a default of 120 seconds instead of docker-py's 60, plus a matching docker-timeout action input. Fixes #42. Fixes #60. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lines Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nealrichardson
force-pushed
the
docker-client
branch
from
October 23, 2026 19:09
0e644a9 to
6cb2949
Compare
Collaborator
Author
|
sure, let's see if this helps |
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.
Fixes #42. Fixes #60.
#42: Docker socket outside /var/run/docker.sock
Problem: docker-py's
from_env()reads onlyDOCKER_HOSTand otherwise uses/var/run/docker.sock. Docker Desktop on macOS, Colima, OrbStack, Rancher Desktop and others put the socket somewhere else, so with-connect fails unless the user setsDOCKER_HOSTby hand.Approach: Instead of hardcoding the Docker Desktop path, use the Docker CLI's current context, which is how the
dockercommand finds the daemon. Every one of those tools registers a context pointing at its socket.DOCKER_HOST, if set, always wins.DOCKER_CONTEXTif set, elsecurrentContextfrom the Docker config (respectingDOCKER_CONFIG). docker-py'sContextAPIdoesn't readDOCKER_CONTEXTitself, so with-connect passes it in.unix://ornpipe://socket that differs from the default socket. Thedefaultcontext,tcp://andssh://contexts, and missing or unreadable context files all fall back to plainfrom_env(), which is what with-connect does today. Remote contexts need TLS certs or SSH options, and supporting those would mean reimplementing more of the CLI. Anyone using one can still setDOCKER_HOSTand theDOCKER_TLS_*variables.from_env(environment=...), a copy ofos.environwithDOCKER_HOSTset, so the process environment stays unchanged.with-connect -- COMMANDtherefore passes the user's environment through untouched.Could not connect to Docker at unix:///... (from the current Docker context). Is it running? ...#60: Docker API timeout fixed at 60 seconds
Problem: docker-py's default per-request timeout is 60 seconds, and with-connect offers no way to change it. On busy CI machines, container create can take longer than that.
Approach:
--docker-timeout SECONDSflag. It takes a positive, finite number and is validated like--port.DOCKER_CLIENT_TIMEOUT, the name docker-compose v1 used for the same setting, so it may already be set in some CI environments. An invalid value is rejected with a usage error that names the variable.docker-timeoutaction input, passed only when set, in both start and stop modes.Per-call timeouts such as
container.stop(timeout=...)are out of scope.Verification
On this machine (Docker Desktop; current context
desktop-linux→unix:///Users/.../.docker/run/docker.sock;/var/run/docker.sockis a symlink to it):DOCKER_HOSTunset,context_docker_host()returns the Docker Desktop socket anddocker_client().version()connects (Engine 29.5.3).DOCKER_CONFIGwhose fake context points at the real socket: the socket is resolved, the client connects, andclient.api.timeoutmatches the requested value.DOCKER_CONTEXTset to a context whose socket doesn't exist:with-connect --stopexits 1 with the one-line "Could not connect to Docker at ..." error.DOCKER_CLIENT_TIMEOUT=x: exit 2 withDOCKER_CLIENT_TIMEOUT: invalid timeout value: 'x'.--docker-timeout 30with a fake license on a random port: the image pull, container create and start, and log polling all went through the context-resolved client. Connect then rejected the license as expected, and the container was stopped.Tests
New tests sit next to
test_docker_unreachable_is_reportedand are registered in the__main__block. They cover:DOCKER_CONFIGDOCKER_CONTEXTtaking precedence overcurrentContextDOCKER_HOSTtaking precedence over bothtcp://,ssh://, no config, a missing context, and a corruptmeta.jsondocker_client()passing the host and timeout through without changingos.environ0,-5,inf,nan,abc, and an invalid env varThe context tests point
HOMEat the temp dir, because docker-py falls back to~/.docker/config.json.uv run test_main.pyanduv run --with pytest pytest -qboth pass (54 tests).Conflicts with other open branches
Checked after rebasing onto the updated #70, which is now rebased onto main (including #69, #71, #74, and #75):
auto-port): merges cleanly.stream-startup-logs): conflicts, so whichever merges second needs a rebase.🤖 Generated with Claude Code