Sohan
Sohan

Reputation: 6809

Unable to make JMX connection remotely when application running under docker

I have application running within jetty container. I have initialized the JMX process under jetty container. These all processes are running under docker container. When i try to make remote connection using JCONSOLE to connect my JMX host:port i am unable to connect.

My physical host machine : matrix01lx (This is where docker container is running) My docker virtual IP address : 172.17.0.2.

Now when i want to connect using JMX i am able to connect, only when i do connection from the physical host where docker container is running i.e. matrix01lx in my case.

I connect using : service:jmx:rmi://host/jndi/rmi://matrix01lx:11041/smp.serverruntime

Remote connection fails when connecting through JCONSOLE saying,

 java.rmi.ConnectException: Connection refused to host: **172.17.0.2**; nested exception is: 
    java.net.ConnectException: Connection timed out: connect
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
    at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:129)
    at javax.management.remote.rmi.RMIServerImpl_Stub.newClient(Unknown Source)
    at javax.management.remote.rmi.RMIConnector.getConnection(RMIConnector.java:2404)
    at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:308)
    at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:268)
    at com.sigma.jmxClient.Connect.main(Connect.java:53)
Caused by: java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:579)
    at java.net.Socket.connect(Socket.java:528)
    at java.net.Socket.<init>(Socket.java:425)
    at java.net.Socket.<init>(Socket.java:208)
    at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
    at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:147)
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
    ... 8 more 

I have refer to forums and tried setting following properties in my MAVEN_OPTS when starting mvn process and explicitly in code as well.

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.rmi.port=11041
-Djava.rmi.server.hostname=matrix01lx (also tried putting IP address here)

Note : I have tried disabling firewall. I am using centOS 7

Please suggest!

Upvotes: 2

Views: 2342

Answers (1)

Sergei Rodionov
Sergei Rodionov

Reputation: 4539

This configuration is known to work for a Java application running in a container.

java.rmi.server.hostname should be the same hostname you're connecting with. Make sure it's resolvable from the originating machine.

-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1090 -Dcom.sun.management.jmxremote.rmi.port=1090 -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=matrix01lx -Dcom.sun.management.jmxremote.password.file=${ACTIVEMQ_CONF}/jmx.password -Dcom.sun.management.jmxremote.access.file=${ACTIVEMQ_CONF}/jmx.access

See a working example for ActiveMQ in container:

https://github.com/axibase/atsd/tree/master/integration/activemq

Upvotes: 2

Related Questions