Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can this tool help me connect port when docker run use --net="host" #8

Open
631068264 opened this issue Feb 27, 2022 · 11 comments
Open

Comments

@631068264
Copy link

No description provided.

@gregnr
Copy link
Member

gregnr commented Feb 28, 2022

Hi @631068264, I assume you are trying to use --net=host so that your container listens on a port from your macOS host instead of the Linux VM host (correct me if I'm wrong).

Currently this package does not solve that, although I can think of some options to make that happen (ie. monitor /proc/net/tcp and iptables on Linux VM and add port forwarding NAT rules on macOS using pfctl). Let me know if you think this would be useful.

In the mean time, you can replace Docker Desktop with Rancher Desktop (using dockerd runtime) which supports --net=host macOS host binding out of the box (via lima). I've been using Rancher Desktop as a drop-in replacement for Docker Desktop for about a month now without issues.

@631068264
Copy link
Author

Thanks for your reply.

I just wanted to find a solution or a tool help me, when use --net=host on OSX can work like in linux. Because I always test my application on local.

I'm not good at these(docker network on OSX, etc) so I'm sorry that I can' tell you sth more valuable. I even don't know how to connect the Linux VM on OSX.

@gregnr
Copy link
Member

gregnr commented Mar 2, 2022

Thanks for clarifying. If you are not tied to the official Docker Desktop, I would give something like Rancher Desktop a try as it supports what you are trying to do.

I'll keep this feature in mind for this package though and let you know if it's gets added in the future.

@alexandertsukanov
Copy link

BTW a very nice feature to have, I have tried to map the docker container somehow to my local machine 127.0.0.1, but don't have success with that.

@dro-ex
Copy link

dro-ex commented Jan 12, 2023

This is exactly what I am looking for as well - if there is a way to do this it would be great. I am specifically running into the issue where the discoverable IoTs are on the host network and home assistant cannot auto discover devices and some devices do not report back due to lack of host networking in docker desktop for mac.

@gregnr
Copy link
Member

gregnr commented Jan 12, 2023

@alexandertsukanov @dro-ex Thanks for the comments.

@dro-ex That's a neat use case - unfortunately I don't think this tool will solve your problem. Assuming Home Assistant uses mDNS to discover devices, mDNS packets can't traverse layer 3 network boundaries, at least not without an mDNS reflector. I haven't been able to find any macOS-based mDNS reflectors yet unfortunately.

FWIW, Rancher Desktop creates a layer 2 bridged network between macOS and the container VM (compared to a layer 3 network on Docker Desktop), which means protocols like mDNS are supported. This means that all you need to do is attach your container to a host or macvlan network to get access to your physical layer 2 LAN network.

I just tried this using --net=host and avahi-browser and successfully got a list of mDNS devices running on my LAN network from inside the container:

$ docker run --net=host hsfeng/avahi-browse --all
...

@dro-ex
Copy link

dro-ex commented Jan 13, 2023

Unless I am overlooking something (amd I am sure I am), the above is not working with home assistant:

nerdctl run -d \         
  --name homeassistant \
  --privileged \
  -e TZ=TZ=America/Los_Angeles \
  -v /Users/test/homeassistant/config:/config \
  --net=host \    
  ghcr.io/home-assistant/home-assistant:stable

I am still getting "no devices on network"

@gregnr
Copy link
Member

gregnr commented Jan 13, 2023

@dro-ex I've never used Home Assistant before, but just gave it a quick try here. For me no devices were discovered at first, but then I realized that the default network interface picked by Home Assistant for discovery was wrong under Settings > System > Network. For me the correct interface for my LAN was rd0 (it had picked eth0). After a restart all my devices started showing up.

Let me know if that helps.

@dro-ex
Copy link

dro-ex commented Jan 14, 2023

It's very strange - I am not getting any network settings in home assistant using Rancher Desktop - just a blank page - no errors. It is working but no -net=hose access. I've tried both nerdctl and docker as engines. I am going to try some different things and see if I can the network settings to show up.

@gregnr
Copy link
Member

gregnr commented Jan 14, 2023

@dro-ex I had to set my profile to "Advanced Mode" to see the Network Settings. See:
https://www.home-assistant.io/integrations/network/

Was also getting a blank screen without that enabled.

@dro-ex
Copy link

dro-ex commented Jan 15, 2023

Thank you! It is indeed discovering local IoT devices - this is such good news. Thank you! I am now trying to learn what I need to to ditch portainer and docker desktop and recreate all the containers in rancher. Thank you again!

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

No branches or pull requests

4 participants