Skip to content

fix: honor active Docker context on macOS when /var/run/docker.sock is unavailable - #538

Merged
Harsh4902 merged 1 commit into
microcks:masterfrom
ish-g09:fix/macos-docker-context
Nov 6, 2026
Merged

Harsh4902 merged 1 commit into
microcks:masterfrom
ish-g09:fix/macos-docker-context

Conversation

@ish-g09

@ish-g09 ish-g09 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

  • Added ConfigureDockerHost in pkg/connectors/container_client.go to help microcks-cli connect to Docker on macOS when the default /var/run/docker.sock isn't available.
  • Checks the active Docker context first via docker context inspect so it honors whatever context the user is actively running (Docker Desktop, Colima, OrbStack, etc.).
  • Adds a fallback to $HOME/.docker/run/docker.sock if context inspection isn't available.
  • Leaves existing behavior completely untouched if DOCKER_HOST is already set or if /var/run/docker.sock exists (like on Linux).
  • Hooked this check into NewDockerClient(), PingDockerHost(), and cmd/testDryRun.go so both microcks start and microcks test --dry-run can reach Docker smoothly on modern macOS setups.
  • Added comprehensive unit tests in pkg/connectors/container_client_test.go covering active context resolution, socket fallback, and platform checks.

Related issue(s)

Fixes #537

AI Disclosure

The code changes and unit tests were verified by me and I fully understand them. Used AI assistance to help structure unit test cases and mock subprocess patterns.

Testing

  • go test -v -run TestConfigureDockerHost ./pkg/connectors/... : passes (6/6 tests)
  • go build ./... : passes
  • go test ./... : all packages pass

Copilot AI lite review requested due to automatic review settings September 23, 2026 06:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Active-context handling has unresolved context-name and TLS/SSH compatibility issues, with missing focused macOS tests.

Review effort: Lite
Findings: None

What changed in this PR

Updates Docker endpoint discovery on macOS to support active contexts and user socket fallbacks.

Changes:

  • Adds Docker context inspection and socket fallback logic.
  • Applies configuration to Docker clients, ping checks, and dry-run execution.
File Summary
pkg/​connectors/​container_client.go Adds Docker host resolution and client integration. Requires context-name resolution, support for TLS/SSH metadata, focused macOS tests, and gofmt cleanup.
cmd/​testDryRun.go Configures the Docker host before dry-run Testcontainers usage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@ish-g09

ish-g09 commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

Hey @Harsh4902,

Just opened this PR for the macOS Docker context discovery, all CI checks are green.
Saw Copilot's summary mention unit tests. Happy to add a container_client_test.go covering DOCKER_HOST precedence and resolution if you'd like. Let me know what you think whenever you get a chance to look!

Comment thread pkg/connectors/container_client.go Resolved
Comment thread pkg/connectors/container_client.go Resolved
@ish-g09

ish-g09 commented Sep 29, 2026

Copy link
Copy Markdown
Contributor Author

Hi @Harsh4902,

Following up from the discussion on #539, I've updated the PR and added unit tests in container_client_test.go to cover the active context inspection, socket fallbacks, and platform checks for ConfigureDockerHost.

Lemme know incase i've missed on something.

Comment thread pkg/connectors/container_client.go Resolved
Comment thread pkg/connectors/container_client.go Resolved
@ish-g09

ish-g09 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor Author

@yada @Harsh4902, whenever you get time pls take a look

@yada

yada commented Oct 28, 2026

Copy link
Copy Markdown
Member

Verified the merge result on macOS (build, go vet, go test ./... pass). With DOCKER_HOST unset and no /var/run/docker.sock (Docker Desktop with the privileged symlink disabled, active context socket at ~/.docker/run/docker.sock):

  • master: microcks start --image alpine:3 --no-wait fails with Cannot connect to the Docker daemon at unix:///var/run/docker.sock (exit 14)
  • this PR: the container is created and start succeeds (exit 0)

So the fix works for the reported case. It is not merged because of Harsh's open change request. His main concern (Sep 23) is to prefer a solution from the Docker SDK over our own fallback, and he asked on Oct 9 why the test hooks are package-level variables. @ish-g09 answered on Oct 9. @Harsh4902: could you tell us whether a bridge solution is acceptable until the SDK offers context support, and re-review? If yes, I would suggest limiting the fallback to macOS and an unset DOCKER_HOST, which it already does.

Disclosure: this comment was drafted with AI assistance, and the results were run locally.

@Caesarsage

Copy link
Copy Markdown
Collaborator

Thanks @ish-g09, and thanks @yada for verifying on macOS. I'm fine taking this as a bridge until we move to docker/go-sdk, since it only runs on darwin with no DOCKER_HOST and no /var/run/docker.sock. @Harsh4902, are you OK with that? A few small changes first:

(1) only apply the inspected endpoint when it starts with unix://; a tcp:// context with TLS or an ssh:// context would give a DOCKER_HOST the Go SDK can't use without the certs or connhelper, so for those it's better to fall through to the socket fallback.

(2) Use exec.CommandContext with a short timeout (for example 3s) so a broken docker binary can't hang start.

(3) Add a // TODO: replace with docker/go-sdk context support so we remember to remove this later.

…able

Signed-off-by: ish-g09 <ig.valiente09@gmail.com>
@ish-g09

ish-g09 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Caesarsage and @yada for the review and verification!
I've pushed an update addressing all three points:

  1. Added the strings.HasPrefix(endpoint, "unix://") check so tcp:// or ssh:// endpoints fall through to the user socket fallback.
  2. Switched to exec.CommandContext with a 3-second timeout (context.WithTimeout) to avoid hanging on a stalled docker CLI.
  3. Added the // TODO: replace with docker/go-sdk context support comment.

I've also updated container_client_test.go and added a unit test covering the non-Unix endpoint fallback. All unit tests pass cleanly :)
Let me know if this looks good or if you'd like me to make any other changes!

@Harsh4902

Copy link
Copy Markdown
Member

Thanks @ish-g09, and thanks @yada for verifying on macOS. I'm fine taking this as a bridge until we move to docker/go-sdk, since it only runs on darwin with no DOCKER_HOST and no /var/run/docker.sock. @Harsh4902, are you OK with that? A few small changes first:

(1) only apply the inspected endpoint when it starts with unix://; a tcp:// context with TLS or an ssh:// context would give a DOCKER_HOST the Go SDK can't use without the certs or connhelper, so for those it's better to fall through to the socket fallback.

(2) Use exec.CommandContext with a short timeout (for example 3s) so a broken docker binary can't hang start.

(3) Add a // TODO: replace with docker/go-sdk context support so we remember to remove this later.

Thanks @Caesarsage, we can go with bridge solution as that's the only option.

@Caesarsage Caesarsage left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ish-g09 for the quick update, and @Harsh4902 for confirming. All three points are addressed and the tests pass. Merging as a stopgap until we move to docker/go-sdk (#539).

@Harsh4902 Harsh4902 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ish-g09, I'm approving these changes.

@Harsh4902
Harsh4902 merged commit 684000a into microcks:master Nov 6, 2026
4 checks passed

This branch was previously deployed

1 inactive deployment
Build — cdf8214e Deployed Oct 30, 2026 by ish-g09 via build-verify-package #843
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS: honor the active Docker context when /var/run/docker.sock is unavailable

5 participants