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.

Related issue(s)

Fixes #537

AI Disclosure

The code changes were written and verified by me. I fully understand them. Took help of AI to check for vulnerabilities.

Testing

  • 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!

…able

Signed-off-by: ish-g09 <ig.valiente09@gmail.com>
// ConfigureDockerHost ensures DOCKER_HOST points to an active Docker daemon socket.
// On macOS, Docker Desktop may not install the privileged /var/run/docker.sock symlink.
// If DOCKER_HOST is not explicitly set, we look for the user socket or inspect the active context.
func ConfigureDockerHost() error {

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.

Hey @ish-g09 This is a good workaround but if you see the codebase carefully, we don't set any DOCKER_HOST value for our docker client. We are using docker's official go-sdk to connect with docker. So ideally a solution should be from the docker sdk side and not a fallback on our side.

return nil
}
func NewDockerClient() (*containerClient, error) {
if err := ConfigureDockerHost(); err != nil {

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.

So, this check should be there only if docker's go-sdk dosen't provide the solution for this. Otherwise it a overhead on us to manage things whenever something is got changed on their end.

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.

Hey @Harsh4902, totally fair point! I actually dug into the Docker Go SDK and re-read the Mac permission docs you linked to check if the SDK could handle this natively.
Interestingly, Docker's docs call out this exact scenario:

"If you don't enable this option, the symlink... is not created and you may have to explicitly set the DOCKER_HOST environment variable to /Users//.docker/run/docker.sock in the clients it is using. The Docker CLI relies on the current context to retrieve the socket path..."

Basically, contexts are managed only by the docker CLI tool, while the Go client SDK (client.FromEnv) just looks for DOCKER_HOST and otherwise hardcodes /var/run/docker.sock. It doesn't know how to resolve contexts on its own.
That's why setting DOCKER_HOST through this small fallback (just like we already do for Podman in ConfigurePodmanHost) seemed like the simplest way to get it working on modern Macs without bringing in heavy CLI packages.

Let me know what you think! Happy to explore other ideas if there's a cleaner way you prefer or incase i've missed something.

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.

@ish-g09 I tried to dig deeper and found Docker has already deprecated it's original github.com/docker/docker go library which we are using currently. They are building a completely new docker go-sdk. And which provides access to low lever docker API and also have cli context so it can work smoothly. But, this sdk is still not in it's v1.0.0 which is basically first stable release. So the adoption of this library is crucial now. Let's think how long can we work with this temporary solution. Then we can adapt that. But for the long run, we anyways have to migrate to new docker go-sdk.

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.

I am also trying to connect with moby maintianers, as old docker go sdk is now transformed into project moby. If they can provide some library level solution then it's well and good. Otherwise we have to go with temporary solution.

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.

Makes total sense @Harsh4902! Happy to wait and see what they suggest. If it turns out they don't have a library-level option right now, we can always revisit this approach as a bridge until the new SDK stabilizes.

Keep me posted on what they say!

This branch was successfully deployed

1 active deployment
Build 31eec2eb Deployed Sep 23, 2026 by ish-g09 via build-verify-package #712
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