0

I’m trying to Dockerize a Java server application , I have two client applications, a graphical interface (GUI) and an emulator.

  1. The emulator runs on a host machine and communicates with the server application running in a Docker container through two ports 10008 - 10009 via TCP protocol.

  2. The graphical interface runs on a host machine and communicates with the server application running in a Docker container through a port 40031 by RMI (Remote method invocation).

First case works fine, I just have to start the application exposing ports 10008 and 10009.

I’m having problems with second case, I can’t make it work. I expose port 40031 in Dockerfile and I run the image mapping ports:

docker run -p 40031:40031 -it 24d52b42ff77 /bin/bash

Then I run the application doing something similar to that:

java -Xms64M -Xmx256M -XX:NewRatio=3 -Djava.rmi.server.hostname=x.x.x.x $timeZoneParameter $cacertParameter -Dlogs.dir=$LOGS_DIR -cp $CLASS_PATH Application > /dev/null 2> /dev/null

When server application starts running it sets RMI on port 40031 correctly, I also checked that client and server establish TCP connection correctly. I have to say that everything runs perfectly without using dokcer.

All the information I founded about RMI is about trying to monitor an application with JMX which is not my case, the solution given is to add certain flags at startup, example:

JMX_PORT = 9010
HOST = "0.0.0.0"
java \
-Dsun.management.jmxremote.level = FINEST \
-Dsun.management.jmxremote.handlers = java.util.logging.ConsoleHandler \
-Djava.util.logging.ConsoleHandler.level = FINEST \
-Dcom.sun.management.jmxremote.local.only = false \
-Dcom.sun.management.jmxremote.ssl = false \
-Dcom.sun.management.jmxremote.authenticate = false \
-Dcom.sun.management.jmxremote.port = $ JMX_PORT \
-Dcom.sun.management.jmxremote.rmi.port = $ JMX_PORT \
-Dcom.sun.management.jmxremote.host = $ HOST \
-Djava.rmi.server.hostname = $ HOST \
-agentlib: jdwp = transport = dt_socket, server = y, suspend = n, address = 5005 \
-jar /opt/app/app.jar

In this case the solution does not give the expected result.

Do you have and idea for solving that problem?

Sources already reviewed to try to solve the problem:

https://github.com/cstroe/java-jmx-in-docker-sample-app

http://adambien.blog/roller/abien/entry/how_to_establish_jmx_connection

Raul Maza
  • 361
  • 3
  • 7
  • 1
    Perhaps [3071376](https://stackoverflow.com/questions/3071376/what-port-is-used-by-java-rmi-connection) may help? – toolkit Mar 09 '20 at 11:58
  • RMI and Docker don't play together very well if you want to connect from outside a container to a RMI server inside a container. Search for JMX and Docker which has RMI as the underlying problem. The root cause, as far as I remember is you trying to connect to the Docker host IP while the RMI server only sees its Docker container IP. – Ralf Mar 09 '20 at 12:09
  • @Ralf Yes, thats what I was thinking I'm trying to connect to the RMI server using host IP and the client is not finding anything there. RMI server is running perfectly inside the container but I can't access it from outside. Mapping is not working. Any ideas? – Raul Maza Mar 09 '20 at 16:30
  • I think you can do RMI over HTTP. But IMHO you are much better off with moving on to REST or SOAP web services. – Ralf Mar 09 '20 at 18:15

0 Answers0