Hi,
I am trying to run a RMI service as a docker swarm service. Here I am facing issue when the registry lookup is happening. I have observed couple of scenarios. I will describe the same below.
When I create a docker swarm service, it will create the docker container for the swarm task. That container has 3 network interfaces.
- Eth0 with 10.255.0.X
- Eth1 with 172.18.0.X
- Loopback with 127.0.0.1
I am using a port 6668 to do port mapping between host and container.
The command I used to create docker swarm service:
docker service create --replicas 1 -p 6668:6668 --name container1 --mount type=bind,source=/opt/RMI,destination=/opt/RMI imagename /opt/rmi/startRmiService.sh 10.255.0.X(ip to set rmi.server.hostname) 6668(port)
-
First scenario: I set -Djava.rmi.server.hostname=172.18.0.X (eth1 ip address of container) inside the container. Then I ran the test client to get the registry using public IP of host and port specified above from outside the container. In this scenario I am getting a connection refused exception. I am suspecting that since there is no service running on that port, its giving the connection refused exception. But why there is no service running? I have given the IP(172.18.0.X) and the port(6668) to start RMI service and it is running inside the container using that IP and port. (Checked using the command ps -ef | grep 6668).
-
Second scenario: I set -Djava.rmi.server.hostname=10.255.0.X(eth0 ip address of container) inside the container. Then I ran the test client to get the registry using public IP of host and port specified above from outside the container. In this scenario I am getting the registry and lookup is also happening. But the problem here is it’s taking more then 2 mins to do RMI lookup after getting the registry.
-
Third scenario: Instead of running swarm service, just created a docker container and set rmi.server.hostname=172.17.0.X (eth0 ip address of conatiner). Then I ran the test client, its working properly. No delay in the getting registry or doing lookup.
Following is the code snippet of test client,
ProxyRMIService proxyRMIService = null;
String rmiName = null;
Registry registry;
try {
registry = LocateRegistry.getRegistry("HostIP", Integer.parseInt("6668"));
String[] boundNames = registry.list();
for(String name : boundNames){
rmiName = name; (This will give "rmi://10.155.0.X (or) 172.19.0.X (or) 172.17.0.X:6668/method_name" based on IP used to set rmi.server.hostname)
System.out.println("bound name"+name);
}
proxyRMIService = (ConfigAgentProxyRMIService) registry.lookup(rmiName);
if(proxyRMIService != null){
System.out.println("Looking up");
}
Can someone please explain me why it is giving connection refused exception when I gave 172.18.0.X IP address and why is taking more time to do look up when I gave 10.255.0.X IP address for rmi.server.hostname when I create docker swarm service to run RMI service?
Please revert back if you need any other information.
Thanks in advance.