Skip to content

fix: resolve docker context when running as root via launchd#81

Merged
gregnr merged 2 commits intomainfrom
fix/docker-context-as-root
Feb 18, 2026
Merged

fix: resolve docker context when running as root via launchd#81
gregnr merged 2 commits intomainfrom
fix/docker-context-as-root

Conversation

@gregnr
Copy link
Member

@gregnr gregnr commented Feb 18, 2026

When installed via Homebrew, the binary runs as a root LaunchDaemon which has no ~/.docker/config.json. This meant docker context resolution always failed, and there was no fallback. So even if you were using the default docker socket, it wouldn't use it.

This fixes the issue by:

  1. Detecting the logged in user via who owns /dev/console, then points DOCKER_CONFIG to their docker config directory before resolving the context
  2. If context resolution still fails, it falls back to client.FromEnv which respects DOCKER_HOST and then the default socket

Test plan

  • sudo ./docker-mac-net-connect works (normal sudo, HOME preserved)
  • sudo -i $(pwd)/docker-mac-net-connect works (simulates launchd with root HOME)
  • Falls back gracefully if no console user or no docker config exists

@gregnr gregnr enabled auto-merge February 18, 2026 22:46
@gregnr gregnr merged commit 50d17a4 into main Feb 18, 2026
5 of 6 checks passed
@gregnr gregnr deleted the fix/docker-context-as-root branch February 18, 2026 23:06
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.

1 participant