diff --git a/docker/constants.py b/docker/constants.py index 0e39dc29..1e001fd3 100644 --- a/docker/constants.py +++ b/docker/constants.py @@ -1,3 +1,4 @@ +import os import sys from .version import __version__ @@ -11,7 +12,14 @@ CONTAINER_LIMITS_KEYS = [ ] DEFAULT_HTTP_HOST = "127.0.0.1" -DEFAULT_UNIX_SOCKET = "http+unix:///var/run/docker.sock" + +# Check for OrbStack socket first, fall back to standard Docker socket +ORBSTACK_SOCKET = os.path.expanduser("~/.orbstack/run/docker.sock") +if os.path.exists(ORBSTACK_SOCKET): + DEFAULT_UNIX_SOCKET = f"http+unix://{ORBSTACK_SOCKET}" +else: + DEFAULT_UNIX_SOCKET = "http+unix:///var/run/docker.sock" + DEFAULT_NPIPE = 'npipe:////./pipe/docker_engine' BYTE_UNITS = { diff --git a/docker/utils/utils.py b/docker/utils/utils.py index f36a3afb..a7ddfcab 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -16,6 +16,7 @@ from ..constants import ( DEFAULT_HTTP_HOST, DEFAULT_NPIPE, DEFAULT_UNIX_SOCKET, + ORBSTACK_SOCKET, ) from ..tls import TLSConfig @@ -235,6 +236,9 @@ def parse_host(addr, is_win32=False, tls=False): if not addr and is_win32: return DEFAULT_NPIPE if not addr or addr.strip() == 'unix://': + # If OrbStack socket exists, use it + if os.path.exists(ORBSTACK_SOCKET): + return f"http+unix://{ORBSTACK_SOCKET}" return DEFAULT_UNIX_SOCKET addr = addr.strip()