I have a Spring Boot application running in a container on a remote machine, which JVM parameters I have to use to connect to it through Java Mission Control or JVisual VM (via JMX)?
Asked
Active
Viewed 4,240 times
1 Answers
8
Start the container with the following JAVA_OPTIONS:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.rmi.port=7012
-Dcom.sun.management.jmxremote.port=7012
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=<public_ip>
Also, make sure you expose the same port you are listening inside the container (e.g. docker run container -p 7012:7012 ...)

Alessandro Dionisi
- 2,494
- 4
- 33
- 37
-
I can't stress enough how IMPORTANT that "same port" remark is. It won't work if that's not the case. – Mihai Todor Aug 23 '18 at 22:00
-
2@MihaiTodor you just solved my problem! All the other instructions on how to connection remotely did not include this "gotcha"! Thanks mate! – Mark Dec 25 '19 at 22:39
-
You're welcome! Even if you're running the container on a remote host and you want to do port forwarding via ssh to connect to it, the port on `localhost` needs to be the same as the port in the container. I'm not sure why that needs to be so, but that's what did the trick for me. – Mihai Todor Dec 26 '19 at 13:13
-
In my case I didn't want to expose JMX port publicly (mapped it as `127.0.0.1:9090:9090` in my docker-compose.yml), and do the ssh port forwarding when accessing it. The thing is that besides the same port "gotcha", I had to set `-Djava.rmi.server.hostname=127.0.0.1` as it didn't work with host's IP nor machine name. – Petar Mitrovic May 27 '20 at 11:14