Connecting a Docker container to a network interface / device instead of an IP address

不问归期 提交于 2019-12-05 23:44:59

问题


After careful research, testing, and fiddling, I've only been able to find away to connect a Docker container to a given interface by forwarding from an IP/port. This can be accomplished by adding -p Host-IP:Host-Port:Container-Port to a docker run command.

I have an app that listens for UDP broadcasts (255.255.255.255), and have been unable to configure forwarding in such a way that my container will receive those broadcasts without forwarding all network traffic on the port I care about (no matter through which interface it comes in), ie: -p Host-Port:Container-Port.

It's possible to configure the container with --net=host and just write my code to bind to a given interface, which I've done and tested, but that still goes against the main idea of a container. The goal is to have multiple containers of the same app listening on different network interfaces (as in devices, not addresses).

Any ideas on how I could do this?

EDIT #1: After thinking about this some more, it may be possible that setting up the bridge over the required interface is enough, but I don't trust the OS to send the broadcast packets over it. Stay tuned as I perform more tests.

EDIT #2: Packets are sent over a bridge just fine. However, the bridge is configured as the Docker default bridge. I haven't been able to figure out how to run containers on different bridges. Saw some notes that point towards setting the network to --net=none and configuring it yourself through lxc container settings.


回答1:


By default docker run command publishes ports for tcp. Try to specify use of udp:

docker run -p Host-Port:Container-Port/udb ...



来源:https://stackoverflow.com/questions/28357274/connecting-a-docker-container-to-a-network-interface-device-instead-of-an-ip-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!