Skip to content

Auto-detect Docker Desktop socket location on macOS #42

@dotNomad

Description

@dotNomad

Problem

On macOS with Docker Desktop, with-connect fails to connect to Docker unless DOCKER_HOST is explicitly set:

docker.errors.DockerException: Error while fetching server API version: 
('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

This happens because the Python Docker SDK (docker.from_env()) looks for the socket at /var/run/docker.sock, but Docker Desktop on macOS places it at ~/.docker/run/docker.sock.

Current workaround

Users must manually set:

export DOCKER_HOST=unix://$HOME/.docker/run/docker.sock

Suggested fix

The docker.from_env() calls at line 134 and line 153 could be wrapped in a helper that auto-detects the macOS Docker Desktop socket:

import platform
import os

def get_docker_client():
    # Auto-detect macOS Docker Desktop socket
    if platform.system() == "Darwin" and not os.environ.get("DOCKER_HOST"):
        mac_socket = os.path.expanduser("~/.docker/run/docker.sock")
        if os.path.exists(mac_socket):
            os.environ["DOCKER_HOST"] = f"unix://{mac_socket}"
    
    return docker.from_env()

This would make with-connect work out-of-the-box on macOS without requiring users to set environment variables.

Environment

  • macOS (Apple Silicon and Intel)
  • Docker Desktop
  • with-connect installed via uv tool install

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions