@@ -16,12 +16,71 @@ extension Process {
1616 set { standardErrorMap. setObject ( NSString ( string: newValue) , forKey: self ) }
1717 }
1818
19- var userDockerSocket : String ? {
20- let home = FileManager . default. homeDirectoryForCurrentUser
21- let userSocketPath = home. path + " /.docker/run/docker.sock "
22- if FileManager . default. fileExists ( atPath: userSocketPath) {
23- return userSocketPath
19+ /// Returns the Docker socket path by checking (in order):
20+ /// 1. Docker context (supports Docker Desktop, OrbStack, Rancher Desktop, Colima, etc.)
21+ /// 2. User-specific socket (~/.docker/run/docker.sock)
22+ /// 3. OrbStack socket (~/.orbstack/run/docker.sock)
23+ /// 4. Colima socket (~/.colima/default/docker.sock)
24+ /// 5. Legacy system socket (/var/run/docker.sock)
25+ var dockerSocket : String ? {
26+ let home = FileManager . default. homeDirectoryForCurrentUser. path
27+ let fileManager = FileManager . default
28+
29+ // 1. Try to get socket from docker context (respects user's configured context)
30+ if let contextSocket = getDockerContextSocket ( ) {
31+ return contextSocket
32+ }
33+
34+ // 2. Fallback to known socket paths
35+ let knownSockets = [
36+ home + " /.docker/run/docker.sock " , // Docker Desktop (new)
37+ home + " /.orbstack/run/docker.sock " , // OrbStack
38+ home + " /.colima/default/docker.sock " , // Colima
39+ " /var/run/docker.sock " , // Legacy/Linux
40+ ]
41+
42+ for socketPath in knownSockets {
43+ if fileManager. fileExists ( atPath: socketPath) {
44+ os_log ( " Found Docker socket at: %{public}@ " , socketPath)
45+ return socketPath
46+ }
2447 }
48+
49+ return nil
50+ }
51+
52+ /// Gets the Docker socket from the current docker context using `docker context inspect`
53+ private func getDockerContextSocket( ) -> String ? {
54+ let task = Foundation . Process ( )
55+ task. launchPath = " /usr/bin/env "
56+ task. arguments = [ " docker " , " context " , " inspect " , " --format " , " {{.Endpoints.docker.Host}} " ]
57+ task. environment = [
58+ " PATH " : ProcessInfo . processInfo. environment [ " PATH " ] ! + " :/usr/local/bin:/opt/local/bin:/opt/homebrew/bin " ,
59+ ]
60+
61+ let pipe = Pipe ( )
62+ task. standardOutput = pipe
63+ task. standardError = FileHandle . nullDevice
64+
65+ do {
66+ try task. run ( )
67+ task. waitUntilExit ( )
68+
69+ if task. terminationStatus == 0 {
70+ let data = pipe. fileHandleForReading. readDataToEndOfFile ( )
71+ if let output = String ( data: data, encoding: . utf8) ? . trimmingCharacters ( in: . whitespacesAndNewlines) ,
72+ output. hasPrefix ( " unix:// " ) {
73+ let socketPath = String ( output. dropFirst ( 7 ) ) // Remove "unix://"
74+ if FileManager . default. fileExists ( atPath: socketPath) {
75+ os_log ( " Docker context socket: %{public}@ " , socketPath)
76+ return socketPath
77+ }
78+ }
79+ }
80+ } catch {
81+ os_log ( " Failed to get docker context: %{public}@ " , error. localizedDescription)
82+ }
83+
2584 return nil
2685 }
2786
@@ -31,16 +90,15 @@ extension Process {
3190 process. launchPath = " /usr/bin/env "
3291 process. arguments = arguments
3392 process. environment = [
34- // Modify PATH to include dirs containing local binaries.
35- " PATH " : ProcessInfo . processInfo. environment [ " PATH " ] ! + " :/usr/local/bin:/opt/local/bin " ,
93+ // Modify PATH to include dirs containing local binaries (including Homebrew on Apple Silicon) .
94+ " PATH " : ProcessInfo . processInfo. environment [ " PATH " ] ! + " :/usr/local/bin:/opt/local/bin:/opt/homebrew/bin " ,
3695 // Don't attempt to download/run arm64 packages because they're not supported.
3796 " DOCKER_DEFAULT_PLATFORM " : " linux/amd64 " ,
3897 ]
3998
40- // Docker-for-Mac allows both /Users/<user>/.docker/run/docker.sock (new)
41- // and /var/run/docker.sock (legacy but supported).
42- if let userDockerSocket = process. userDockerSocket {
43- process. environment ? [ " DOCKER_HOST " ] = " unix:// " + userDockerSocket
99+ // Set Docker socket from context or known paths (supports Docker Desktop, OrbStack, Colima, etc.)
100+ if let dockerSocket = process. dockerSocket {
101+ process. environment ? [ " DOCKER_HOST " ] = " unix:// " + dockerSocket
44102 }
45103
46104 os_log ( " Running command: %{public}@ " , arguments. joined ( separator: " " ) . scrubHashes ( ) )
0 commit comments