'How do I create a container with multiple network interfaces for different functions?
I can't find the best answers to this, hence I'm posting my question here.
How can I create a container with multiple network interfaces?
- 1st network expose the port so that others can access;
- 2nd network the container needs to access a gateway device;
------------------- -----------------------
----------- .---| port:3000 exposed |---| host / lan can access |
| container |----< ------------------- -----------------------
----------- '_ ------------------- -----------------------
'-| 192.168.1.0/24 |---| access to 192.168.1.1 |
------------------- -----------------------
I have atleast 3 network interface on my host, wlan0, eth0, eth1(usb-lan adapter).
I have the gateway connected on eth1. eth0 is where i need to expose the container port. wlan0 used for management of the host thru ssh.
Is this possible within the container? I'm open to docker or docker-compose solution.
Solution 1:[1]
I'm going to mark this as an answer since there is no possible way to do it in current version of docker / docker-compose.
Anyway, the way I solved this is instead of working with network interfaces, i created a simple systemd service, for ex. i need to send command to the gateway, so i made a simple script that runs in the background and READS a common file that is shared between the HOST and CONTAINER. This is possible since we can mount volume and share that file. CONTAINER will write to file "SEND", then HOST can read it and executes command, when it finishes that task HOST will update the file and write "DONE".
This mechanism seems to work to what i need.
PS. I dont know what to call on this procedure, latch-release, idk, but i'm interested learning this kind of concept. PPS. Hope there will be future update to docker to support multiple network interface.
Solution 2:[2]
You can use multiple -p:
-p WANIP:PORT:CONTAINERPORT/tcp -p INTERNALIP:PORT:CONTAINERPORT
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ritsard |
| Solution 2 | bguiz |
