Skip to content

Resolve default endpoint from docker CLI context#603

Open
ebriney wants to merge 4 commits into
upserve:masterfrom
ebriney:feat/docker-context-resolution
Open

Resolve default endpoint from docker CLI context#603
ebriney wants to merge 4 commits into
upserve:masterfrom
ebriney:feat/docker-context-resolution

Conversation

@ebriney
Copy link
Copy Markdown

@ebriney ebriney commented May 28, 2026

Summary

Make Docker.url mirror the docker CLI when neither DOCKER_URL nor DOCKER_HOST is set: read the current context from $DOCKER_CONFIG/config.json (default ~/.docker/config.json) and pull Endpoints.docker.Host from the context's meta.json. Falls back to unix:///var/run/docker.sock when no usable context is found.

Resolution order is now:

  1. DOCKER_URL
  2. DOCKER_HOST
  3. DOCKER_CONTEXT env, otherwise currentContext from config.json
  4. unix:///var/run/docker.sock

This means users with Docker Desktop, Colima, OrbStack, rootless setups, etc. — which all install their endpoint under a non-default context — no longer need to manually export DOCKER_HOST for the gem to find the daemon.

Notes

  • Kill switch: DOCKER_API_SKIP_CONTEXT=1 disables step 3 and restores the previous behavior (env vars + default socket only).
  • TLS: only the endpoint URL is read from the context. TLS material still comes from DOCKER_CERT_PATH / DOCKER_SSL_VERIFY (unchanged). Per-context TLS material could be a follow-up if there's demand.
  • Errors: missing config file, missing meta file, unparseable JSON, and a context named default all cleanly fall through to the next step — a broken config never raises from Docker.url.
  • DOCKER_CONFIG env var is honored.

Test plan

  • 7 new specs in spec/docker_spec.rb cover: currentContext lookup, DOCKER_CONTEXT override, the default context, missing config.json, missing meta.json, env precedence over context, and the kill switch.
  • Existing default-URL spec is unaffected (one extra stub added so it stays deterministic on dev machines that have a real ~/.docker/config.json).
  • Manually verified against a Docker Desktop install: Docker.url, Docker.version, and Docker.info match docker info exactly (same endpoint unix:///Users/.../docker/run/docker.sock, same Server Version / OS / Name / container/image counts).

🤖 Generated with Claude Code

ebriney and others added 4 commits May 20, 2026 12:21
Match docker CLI lookup when neither DOCKER_URL nor DOCKER_HOST is set:
read DOCKER_CONTEXT (or currentContext from $DOCKER_CONFIG/config.json,
defaulting to ~/.docker/config.json) and pull Endpoints.docker.Host from
the context's meta.json. Falls back to the default unix socket when no
context is configured, the context is named "default", or any file is
missing or unparseable. Set DOCKER_API_SKIP_CONTEXT=1 to disable.

TLS material is still sourced from DOCKER_CERT_PATH; only the endpoint
URL is read from the context.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Explain the DOCKER_URL → DOCKER_HOST → docker CLI context → default
socket lookup, the DOCKER_CONFIG / DOCKER_CONTEXT overrides, and the
DOCKER_API_SKIP_CONTEXT kill switch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Recognize the npipe:// URL scheme so docker-api can talk to the Docker
engine over a Windows named pipe. Docker::Connection parses npipe:// URLs
into a :socket path, lazy-loads a small Excon::Connection patch that
dispatches the scheme to a Docker::NPipeSocket, and the socket itself
opens the pipe through CreateFile/ReadFile/WriteFile via ffi.

Also defaults the endpoint to npipe:////./pipe/docker_engine on Windows
when neither DOCKER_URL/DOCKER_HOST nor a docker CLI context resolves an
endpoint -- matching the docker CLI default on that platform.

The ffi dependency is only loaded when an npipe URL is actually used,
so non-Windows users pay no runtime cost.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Note the platform-conditional default endpoint and the npipe:// URL
form callers can use to point at a custom pipe.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant