简体   繁体   中英

Can I connect VisualVM to remote Java process in Docker without exposing the RMI port as itself?

I've been able to connect VisualVM to my Java process, running in a Docker container, doing something as

docker run \
--rm \
--entrypoint=java \ 
-p 9010:9010 \
my-user/my-image \
-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=9010 \
-Dcom.sun.management.jmxremote.rmi.port=9010 \
-Dcom.sun.management.jmxremote.local.only=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-Djava.rmi.server.hostname='192.168.99.100' \
-jar /my-app-1.0-SNAPSHOT.jar

I have a couple problems with this solution, though:

  1. I don't like having to specify the hostname, as I would like to use the same scripts for running my process in my dev machine and in my different servers

  2. This works if I only want to monitor one JVM. But I'm using a Docker Compose file to my Java app as a service that can be scaled to multiple containers, so I can expose port 9010 but it will be linked to different port numbers in the host

I've been playing with SSH tunnels, but with no luck. The JVM doesn't like being accessed from port 32878, ie, even if it's mapped to 9010 in the container.

Any ideas, please?

I use docker with a wide cluster of web applications and rest services. To access them directly into my local browser (i'm windows 10 user) i have installed proxy container. That proxy have one exposed port "1080:1080". Then i go to my browser with proxy plugin (FoxyProxy). And i can access any port any address. Use that and you don't need to do any other port mapping on other containers, the proxy handles all traffic.

that is the command i use in the container

service sshd start && sshpass -p 'password' ssh -o StrictHostKeyChecking=no -N -D 0.0.0.0:1080 localhost

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM