Images: myprojects, listener
Containers: A, B, C
in myproject there are bunch of project that communicate using telnet and other protocols and I need two of those project to run. So I can't just run them in host because when one of the projects is running, the other project will results in error of "Can't bind ... already in used". hence I need to run to container of myprojects.
A and B will with no issue with the below command:
sudo docker run -itd --name A --privileged myprojects:1.0 bash run.sh
and also I can see the ports with lsof -i
in A and B.
in other image, in listener there is a project which will Read/Write to those port which I'm written. The real problem is if I used --network=host
to creating containers from images, some port will be used by A need to be available for inner-projects in B, but there are not available and it doesn't run.
What I want is, I want to map those ports on A and B to those ports on C and then the project in A and B are just map these ports and doesn't have any conflict with each other ports, so the inner-projects will run successfully and the project in C can listen to those 6 ports.
P.S: It's important to mention that, the C container will communicate with a device on ip:192.168.10.2.
Example
as David Maze pointed out, here is an example of how I run the containers:
sudo docker run -itd --name A --privileged myprojects:1.0
sudo docker run --itd --name B --privileged myprojects:1.0
sudo docker run --itd --name C --privileged listener:1.0
I can NOT use --network=host
because if I do that, the inner-projects in A and B will have be conflict in shared ports, like localhost: 1111 -> localhost: 1212
and etc.
Also I need to connect a device on IP:192.168.10.2 to C and I can't even do that. I tried sudo docker run -itd --name C --privileged --ip 192.168.10.2 listener:1.0
and it's runs fine and I can even get results from ping 192.168.10.2
, but the device does not recognized while in the host, it can be recognized! I think that ping 192.168.10.2
give me results from container not the ping on the host (or I don't know, because I'm a newbie in docker world...).