0

I am running a docker server container attached to the server_router network (bridge network driver) and a docker client container attached to the client_router network (bridge network driver). Router container is connected to both server_router and client_router network.

I need this network topology where server and client belong to different docker networks and router is able to connect the server and client containers (actual router which can route server and client traffic). This is needed for network simulation where i am running the simulation on docker containers instead of actual computers. (network simulator being used is TCP Experiment Automation Controlled Using Python (TEACUP) ).

commands used to create the setup:

docker network create server_router
docker network create client_router
docker run -itd --net client_router --name client ubuntu:14.04
docker run -itd --net server_router --name server ubuntu:14.04
docker run -itd --net server_router --name router ubuntu:14.04
docker network connect client_router router
docker network inspect client_router
docker network inspect server_router

representation of the network topology

I am able to ping client container from router container and vice versa, also I am able to ping server container from router container and vice versa (as they belong to the same network). But I am not able to ping server container from client container and vice versa.

ping command does not show any result.

Any suggestions will be of great help.

sharath
  • 33
  • 5

2 Answers2

0

It is because you forgot to add network connection from client_router to server

 $ docker network connect client_router server

I was able to run things successfully with the following commands.

 $ docker network create server_router
 $ docker network create client_router
 $ docker run -itd --net client_router -h client --name client ubuntu:xenial
 $ docker run -itd --net server_router -h server --name server ubuntu:xenial
 $ docker run -itd --net server_router -h router --name router ubuntu:xenial
 $ docker network connect client_router router   
 $ docker network connect client_router server

and then able to ping successfully from client to the server

 viswesn@viswesn:~$ docker exec -it client bash
 root@client:/# ping server
 PING server (172.22.0.3) 56(84) bytes of data.
 64 bytes from server.client_router (172.22.0.3): icmp_seq=1 ttl=64 time=0.072 ms
 64 bytes from server.client_router (172.22.0.3): icmp_seq=2 ttl=64 time=0.048 ms
 64 bytes from server.client_router (172.22.0.3): icmp_seq=3 ttl=64 time=0.052 ms
 ^C
Viswesn
  • 4,674
  • 2
  • 28
  • 45
  • By adding that line you are creating a link between server and client_router. Here i am looking for communicating with server and client via router container. – sharath Dec 07 '17 at 06:15
  • OMG! you are expecting router Docker to behave like the real router? Then you need to bring vrouter not simple ubuntu machine and behave like router; Its name you have given and don't expect that ubunut docker will behave like vrouter by name :) – Viswesn Dec 07 '17 at 06:44
  • what could i do to make this work :D. will changing default gateway for both the routers and changing the iptable rules inside the router container do the job? – sharath Dec 07 '17 at 07:10
0

OK if this is for mockup and testing, let's list the actions you'll likely need to check off:

  1. You'd need to ensure the router is setup to route IP packets between the two virtual networks.
  2. You'd need to hardcode IP subnets during network creation.
  3. You'd need to hardcode routes during router creation.
  4. Because the default gateway of client and server are not the router container, you'd need to manually add routes to those containers to know they need to go through the router to talk to each other.
  5. You'd need to manually edit host files in client and server if you want to address them by name.
  6. You'd need to manually identify IP's of each container for above DNS to work.

And likely more steps I'm forgetting...

Bret Fisher
  • 8,164
  • 2
  • 31
  • 36
  • I added the gateway ip to the router's interface on both sides (server and client) and it solved my problem. Thank you! – sharath Dec 07 '17 at 15:54
  • @sharath Can you tell more details about your solution because I just met the same problem. – Joe Lu Nov 29 '18 at 20:30