Skip to content

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

Open
ish-g09 wants to merge 1 commit into
microcks:masterfrom
ish-g09:fix/macos-docker-context
Open

ish-g09 wants to merge 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
Comment thread pkg/connectors/container_client.go
@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 Outdated
Comment on lines +78 to +82
var (
currentGOOS = runtime.GOOS
execCommand = exec.Command
defaultSocketPath = "/var/run/docker.sock"
)

@Harsh4902 Harsh4902 Sep 30, 2026 •

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.

Why do we need these extra variables?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

They were added as test hooks so container_client_test.go can mock exec.Command and test the macOS context inspection and socket fallback scenarios on Linux CI runners (without needing a live Docker daemon).

If you'd prefer to keep container_client.go free of package-level test variables and keep the tests simpler, happy to remove them , let me know what u think.

…able

Signed-off-by: ish-g09 <ig.valiente09@gmail.com>
@ish-g09
ish-g09 force-pushed the fix/macos-docker-context branch from fa22049 to 21f7bbd Compare October 1, 2026 06:23
@ish-g09
ish-g09 requested a review from Harsh4902 October 2, 2026 07:21

This branch was successfully deployed

1 active deployment
Build — 21f7bbd8 Deployed Oct 1, 2026 by ish-g09 via build-verify-package #759
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.

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

3 participants