Running RMI service as a docker swarm service

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.

  1. Eth0 with 10.255.0.X
  2. Eth1 with 172.18.0.X
  3. 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)

  1. 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).

  2. 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.

  3. 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.

Found the reason why its not working when we set 172.18.0.X (docker_gwbridge network) IP to rmi.server.hostname. Its a simple docker bridge, but it does not work exactly like docker0 bridge. It just provides a connection between host and container. unlike the docker0 bridge, it is not used to connect to the external network. For Docker Swarm services that publishes ports (with the -p option), Docker creates a dedicated ‘ingress’ network for it.

More information on below link…

Now the second question why its taking so much time to do lookup when we use 10.255.0.X ip (Ingress network)?