0

I have the a docker container (Name CON1) running in the host A, this container is a java RMI server listening on port 1099. I also have another the container (Name CON2) running a java RMI client in the host B. When I telnet CON1 from CON2 using the RMI port 1099 it works fine:

$ telnet 172.30.34.74 1099
  Trying 172.30.34.74...
  Connected to 172.30.34.74.
  Escape character is '^]'.

But when I try to connect through the java RMI client the connection is refused and the error message shows a different IP address for CON1.

java.rmi.ConnectException: Connection refused to host: 172.18.0.2; nested exception is: 
java.net.ConnectException: Connection refused (Connection refused)

Although I use 172.30.34.74 to make the lookop in the RMI client code, the error message shows other IP address (172.18.0.2). When I run the RMI server and the RMI client outside a docker container it works good.

What can I check to solve this situation?

RDV
  • 193
  • 1
  • 3
  • 16
  • Why did Telnet try 172.30.34.74 when you told it 172.18.0.2? And, if that works, why aren't you using 172.18.0.2 in the RMI client code? – user207421 Apr 05 '19 at 04:38
  • The IP address I need to reach is 172.30.34.74. This is what I used when lookup the RMI server. However, for reasons that I don't know, the error stack trace shows the IP address 172.18.0.2. – RDV Apr 05 '19 at 12:34
  • I already saw the mistake that caused confusion. I corrected the original question, the part of the telnet command. I'm sorry for that. – RDV Apr 05 '19 at 12:59

1 Answers1

0

I implemented a solution:

  1. Add to the java command line to start the RMI server the argument -Djava.rmi.server.hostname=HOST_IP. Where host HOST_IP is the host IP.
  2. Set the container's network_mode to host. This way, the container would take same IP as host.
RDV
  • 193
  • 1
  • 3
  • 16