chipmk / docker-mac-net-connect

Connect directly to Docker-for-Mac containers via IP address 🐳 💻
MIT License
407 stars 42 forks source link

failed to create wgctrl client #42

Open KauzClay opened 2 hours ago

KauzClay commented 2 hours ago

Context

I just installed docker-mac-net-connect with brew, but I'm having issues getting things to work.

I've been trying to follow the usage example, but I end up timing out during the curl:

❯ docker run --rm --name nginx -d nginx
973ce2e29801b0e92b1f401da4e09b7a1626258feab08714a588778e597937ee

❯ docker inspect nginx --format '{{.NetworkSettings.IPAddress}}'
172.17.0.2

❯ curl -I 172.17.0.2 -vvv
*   Trying 172.17.0.2:80...
* connect to 172.17.0.2 port 80 from 10.33.33.1 port 58485 failed: Operation timed out
* Failed to connect to 172.17.0.2 port 80 after 75021 ms: Couldn't connect to server
* Closing connection
curl: (28) Failed to connect to 172.17.0.2 port 80 after 75021 ms: Couldn't connect to server

Logs and Details

I started up with sudo brew services start chipmk/tap/docker-mac-net-connect.

sudo brew services ls showed that it had started.

I checked what netstat had to say:

❯ sudo netstat -rnf inet | grep utun
Password:
default            10.229.34.111      UGScg               utun5
default            link#20            UCSIg               utun0
10.4.0.102         10.4.0.102         UH                  utun0
10.33.33.2         10.33.33.1         UH                  utun6
34.117.217.74      link#20            UHWIig              utun0
35.190.88.7        link#20            UHWIig              utun0
135.36.16.158      10.229.34.111      UGHS                utun5
135.142.144.33     10.229.34.111      UGHS                utun5
140.82.112.25      link#20            UHWIig              utun0
172.17             utun6              USc                 utun6 <--------- this looks like what I would expect
192.19.189.10      10.229.34.111      UGHS                utun5
192.19.189.30      10.229.34.111      UGHS                utun5
199.19.250.205     link#20            UHWIig              utun0
224.0.0/4          link#19            UmCS                utun5
224.0.0/4          link#20            UmCSI               utun0
255.255.255.255/32 link#19            UCS                 utun5
255.255.255.255/32 link#20            UCSI                utun0

I also tried the debug steps added by @danbarker and ran the thing directly. This is what I see:

❯ sudo /usr/local/opt/docker-mac-net-connect/bin/docker-mac-net-connect
docker-mac-net-connect version 'v0.1.3'
DEBUG: (utun6) 2024/09/24 15:45:31 Device started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: handshake worker 12 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: decryption worker 4 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: encryption worker 10 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: encryption worker 7 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: encryption worker 1 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: decryption worker 9 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: handshake worker 4 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: decryption worker 1 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: decryption worker 7 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: handshake worker 7 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: encryption worker 11 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: encryption worker 5 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: decryption worker 5 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: encryption worker 8 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: encryption worker 12 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: handshake worker 5 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: decryption worker 8 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: handshake worker 9 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: encryption worker 6 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: handshake worker 8 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: encryption worker 9 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: decryption worker 6 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: handshake worker 6 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: decryption worker 2 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: handshake worker 11 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: decryption worker 10 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: handshake worker 1 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: handshake worker 10 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: decryption worker 11 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: encryption worker 3 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: encryption worker 4 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: decryption worker 3 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: encryption worker 2 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: handshake worker 2 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: handshake worker 3 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: decryption worker 12 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: TUN reader - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: event worker - started
DEBUG: (utun6) 2024/09/24 15:45:31 Interface up requested
DEBUG: (utun6) 2024/09/24 15:45:31 UAPI listener started
DEBUG: (utun6) 2024/09/24 15:45:31 UDP bind has been updated
DEBUG: (utun6) 2024/09/24 15:45:31 Interface state was Down, requested Up, now Up
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: receive incoming v4 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: receive incoming v6 - started
DEBUG: (utun6) 2024/09/24 15:45:31 UAPI: Updating private key
DEBUG: (utun6) 2024/09/24 15:45:31 UAPI: Updating listen port
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: receive incoming v4 - stopped
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: receive incoming v6 - stopped
DEBUG: (utun6) 2024/09/24 15:45:31 UDP bind has been updated
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: receive incoming v4 - started
DEBUG: (utun6) 2024/09/24 15:45:31 Routine: receive incoming v6 - started
DEBUG: (utun6) 2024/09/24 15:45:31 peer(oYJw…awA0) - Starting
DEBUG: (utun6) 2024/09/24 15:45:31 peer(oYJw…awA0) - UAPI: Created
DEBUG: (utun6) 2024/09/24 15:45:31 peer(oYJw…awA0) - UAPI: Adding allowedip
DEBUG: (utun6) 2024/09/24 15:45:31 peer(oYJw…awA0) - UAPI: Adding allowedip
DEBUG: (utun6) 2024/09/24 15:45:31 peer(oYJw…awA0) - Routine: sequential sender - started
DEBUG: (utun6) 2024/09/24 15:45:31 peer(oYJw…awA0) - Routine: sequential receiver - started
DEBUG: (utun6) 2024/09/24 15:45:31 Interface utun6 created
DEBUG: (utun6) 2024/09/24 15:45:31 Wireguard server listening
DEBUG: (utun6) 2024/09/24 15:45:31 Setting up Wireguard on Docker Desktop VM
Interface chip0 already exists. Removing.
Creating WireGuard interface chip0
Assigning IP to WireGuard interface
Failed to create wgctrl client: setnonblock: bad file descriptor
Setup container complete
Adding route for 172.17.0.0/16 -> utun6 (bridge)
DEBUG: (utun6) 2024/09/24 15:45:32 Watching Docker events

This line seems to stick out:

Failed to create wgctrl client: setnonblock: bad file descriptor

Based on what I see in the repo, the code in main.go ends up running a docker container with the client, and I believe the client is failing here.

Any ideas what might be going on here?

Versions

KauzClay commented 2 hours ago

I'm not sure if this is related, but I also noticed that in the docker desktop Images menu, it lists the setup image with a warning: ARM64. image

The image is multi-arch according though, so maybe something is going weird there too?

❯ docker buildx imagetools inspect ghcr.io/chipmk/docker-mac-net-connect/setup
Name:      ghcr.io/chipmk/docker-mac-net-connect/setup:latest
MediaType: application/vnd.docker.distribution.manifest.list.v2+json
Digest:    sha256:fcb4b57d27170baafdd52448f7a2a976f74e23e4c7bc4d63b0a36e8e51736ad7

Manifests:
  Name:      ghcr.io/chipmk/docker-mac-net-connect/setup:latest@sha256:a00fbc4ab54abea09aeea017edcbe334c5fb2a26769af6cc3b3f5501640940b4
  MediaType: application/vnd.docker.distribution.manifest.v2+json
  Platform:  linux/amd64

  Name:      ghcr.io/chipmk/docker-mac-net-connect/setup:latest@sha256:b97b76d837642207600dd346efdd0547127abd3f1603252445cecafb6fd60373
  MediaType: application/vnd.docker.distribution.manifest.v2+json
  Platform:  linux/arm64
gregnr commented 8 minutes ago

Hey @KauzClay thanks for reporting. Does the ARM64 warning provide any further details (eg. it will try to emulate ARM)? Strange indeed that it gives the warning since the image includes amd64 as you pointed out.

You're the first to report this error, so I'm suspicious it could be related to one or a combination of macOS Sonoma + x64 arch (but could also be unrelated). If Docker is trying to emulate ARM for some reason that could potentially cause problems.

KauzClay commented 1 minute ago

hey @gregnr , yes there is more info, hovering over shows:

Image may have poor performance, or fail, if run via emulation