简体   繁体   English

我可以将VisualVM连接到Docker中的远程Java进程而不将RMI端口暴露为自身吗?

[英]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 我已经能够将VisualVM连接到我的Java进程,在Docker容器中运行,做一些事情

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. 如果我只想监视一个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 但是我在我的Java应用程序中使用Docker Compose文件作为可以扩展到多个容器的服务,因此我可以公开端口9010但它将链接到主机中的不同端口号

I've been playing with SSH tunnels, but with no luck. 我一直在玩SSH隧道,但没有运气。 The JVM doesn't like being accessed from port 32878, ie, even if it's mapped to 9010 in the container. JVM不喜欢从端口32878访问,即,即使它映射到容器中的9010。

Any ideas, please? 请问有什么想法吗?

I use docker with a wide cluster of web applications and rest services. 我使用docker与广泛的Web应用程序和休息服务集群。 To access them directly into my local browser (i'm windows 10 user) i have installed proxy container. 要直接访问我的本地浏览器(我是Windows 10用户),我已经安装了代理容器。 That proxy have one exposed port "1080:1080". 该代理有一个暴露的端口“1080:1080”。 Then i go to my browser with proxy plugin (FoxyProxy). 然后我用代理插件(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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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