jpetazzo / pipework

Software-Defined Networking tools for LXC (LinuX Containers)
Apache License 2.0
4.21k stars 727 forks source link

Connecting VM guest with Docker containers running on the same host #253

Closed IvanRibakov closed 8 months ago

IvanRibakov commented 8 months ago

Hi, I'm a backend developer with a limited networks knowledge. I'm in a situation where I need to test a SIP system consisting of several components (various SIP and media elements, SIP UAs) locally on my machine (Linux host). The challenge is that some of the system elements are accessible to me as VMs (I'm using VirtualBox) while others as Docker containers (running via Docker Engine). What I'm trying to understand is whether this project can help me configure my local host and/or VM and Docker guests to ensure that VMs can talk to the Docker containers and vice-versa. I don't have any strong requirements for whether all system components must reside in the same subnet or several different ones as long as cross-communication without NAT is possible (NAT makes things especially difficult when dealing with media protocols).

Am I looking in the right place? If so, can someone please point me to one of the multitude of README scenarios that is closest to what I'm trying to achieve?

jpetazzo commented 8 months ago

Hi Ivan,

That's a pretty interesting challenge!

If the Docker containers are all using different port numbers, my personal approach would be to run them with "host network" (docker run --net host ...). They will use the network stack of the Docker host, which will ensure that there is no NAT at all (at least, not at the level of Docker; VirtualBox might be another story).

If some Docker containers use the same port numbers (e.g. if you have multiple SIP components listening on 5060/udp), things get more "interesting" (read: complicated :)). Since you mentioned that you had limited networks knowledge, my personal approach would be to keep things as simple as possible, and perhaps try to put all the components (VMs and containers) on the same subnet. To put the containers on the same subnet, I would put them in a VM (i.e. run Docker in a VM right next to the other VMs), and then indeed I could use pipework to give them an IP address with DHCP (assuming that VirtualBox is happy to assign IP addresses using DHCP - I'm not 100% sure about that as I haven't used it in a while). The pipework README covers these steps (check the "virtualbox" and "DHCP" sections).

Of course, there are certainly other ways to do that. And perhaps simpler ones, too; but I hope this helps!