无法将 jmx 连接到远程主机上 docker 中的 java app 运行

Cannot connect jmx to java app running in docker on remote host

假设我的本地网络中有一台服务器,IP 为 192.168.100.10。 其中有 docker 容器 运行 和 java 应用程序。 现在我想从我的 IP 地址为 192.168.100.20 的计算机上使用 VisualVM 连接到这个 java 应用程序。我以为我已经正确配置了所有内容,但仍然无法正常工作。

我已经通过了这些 JVM 选项:

   -Dcom.sun.management.jmxremote"
   -Dcom.sun.management.jmxremote.port=9010"
   -Dcom.sun.management.jmxremote.authenticate=false"
   -Dcom.sun.management.jmxremote.ssl=false"
   -Dcom.sun.management.jmxremote.local.only=false"
   -Dcom.sun.management.jmxremote.rmi.port=9010"
   -Djava.rmi.server.hostname=192.168.100.10"

然后我在Dockerfile中暴露了9010端口:

EXPOSE 9010

然后将此端口添加到 docker-compose:

    ports:
      - "9010:9010"

我正在尝试从我的本地计算机使用 JConsole 或 VisualVM 连接到远程主机。在 JConsole 的 "Remote Process" 输入中,我输入了“192.168.100.10:9010”,但连接失败并出现错误: "The connection to 192.168.100.10:9010 did not succeed. Would you like to try again?"

我做错了什么?

上面的解决方案足够有效。我一直在使用环境变量来设置无法正常工作的端口号。