chipmk / docker-mac-net-connect

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

Add dockercli context awareness #11

Open redradrat opened 2 years ago

redradrat commented 2 years ago

So this is just a rough idea, as I wanted to use your tool with colima. Basically I wanted it to just work® with whatever I set as my current context in the actual docker cli.

This current implementation is ugly AF, but it works for me... so figured I'mma send you the PR to see if you'd be interested in the general idea.

gregnr commented 2 years ago

Hey @redradrat, thank you for the idea and PR! I think this is a great enhancement to the lib and has no drawback from what I can see.

Can you confirm if this PR still works in a vanilla setup where the user hasn't created anything beyond the default context? I assume so, but would like to confirm.

redradrat commented 2 years ago

So the default context will work, as well as not having a context set, then it would just assume the default host. But this needs a build and more testing... I'm not sure if I get to it... I kinda just made this so I can get on with things ^^

The problem is, if there is no existing docker config, I think it would initialize a blank one... not sure if that's good. Sure... it's unlikely, as I think we can expect the cli client to be in place, because you would only use this helper if you'd be running docker on mac. So that means you probably have booted up the VM by using docker. But still...

redradrat commented 2 years ago

So it doesn't actually initialise the .docker config dir. It just assumes a "default" docker context. Which is the desired behaviour, I think.

night0wl commented 1 year ago

I did a bit of digging on this one.

When I run the binary manually using sudo it correctly resolved the current context defined in /Users/<me>/.docker, but when I run it as a brew service it tried to derive the context from /var/root/.docker which doesn't exist, so it always resolves to the default socket.

The only docker server I've tested that doesn't support using the default socket is Colima, which seems to have made a design choice not to, and tells users to manually create a symlink, which is what I've been doing.