I’m trying to Dockerize
a Java server application , I have two client applications, a graphical interface (GUI) and an emulator.
The emulator runs on a host machine and communicates with the server application running in a Docker container through two ports
10008 - 10009
viaTCP protocol
.The graphical interface runs on a host machine and communicates with the server application running in a Docker container through a port
40031
byRMI
(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