title: How to access JMX interface in docker from outside?
body: <p>I am trying to remotely monitor a JVM running in docker.  The configuration looks like this:</p>
  
  <ul>
  <li><p>machine 1: runs a JVM (in my case, running kafka) in docker on an ubuntu machine; the IP of this machine is 10.0.1.201; the application running in docker is at 172.17.0.85.  </p></li>
  <li><p>machine 2: runs JMX monitoring</p></li>
  </ul>
  
  <p>Note that when I run JMX monitoring from machine 2, it fails with a version of the following error (note: the same error occurs when I run jconsole, jvisualvm, jmxtrans, and node-jmx/npm:jmx):</p>
  
  <p>The stack trace upon failing looks something like the following for each of the JMX monitoring tools:</p>
  
  <pre><code>java.rmi.ConnectException: Connection refused to host: 172.17.0.85; nested exception is
      java.net.ConnectException: Operation timed out
      at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
      (followed by a large stack trace)
  </code></pre>
  
  <p>Now the interesting part is when I run the same tools (jconsole, jvisualvm, jmxtrans, and node-jmx/npm:jmx) on the same machine that is running docker (machine 1 from above) the JMX monitoring works properly.  </p>
  
  <p>I think this suggests that my JMX port is active and working properly, but that when I execute JMX monitoring remotely (from machine 2) it looks like the JMX tool does not recognize the internal docker IP (172.17.0.85)</p>
  
  <p>Below are the relevant (I think) network configuration elements on machine 1 where JMX monitoring works (note the docker ip, 172.17.42.1):</p>
  
  <pre><code>docker0   Link encap:Ethernet  HWaddr ...
        inet addr:172.17.42.1  Bcast:0.0.0.0  Mask:255.255.0.0
        inet6 addr:... Scope:Link
        UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
        RX packets:6787941 errors:0 dropped:0 overruns:0 frame:0
        TX packets:4875190 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:0
        RX bytes:1907319636 (1.9 GB)  TX bytes:639691630 (639.6 MB)
  
  wlan0     Link encap:Ethernet  HWaddr ... 
        inet addr:10.0.1.201  Bcast:10.0.1.255  Mask:255.255.255.0
        inet6 addr:... Scope:Link
        UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
        RX packets:4054252 errors:0 dropped:66 overruns:0 frame:0
        TX packets:2447230 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:1000
        RX bytes:2421399498 (2.4 GB)  TX bytes:1672522315 (1.6 GB)
  </code></pre>
  
  <p>And this is the relevant network configuration elements on the remote machine (machine 2) from which I am getting the JMX errors:</p>
  
  <pre><code>lo0: flags=8049&lt;UP,LOOPBACK,RUNNING,MULTICAST&gt; mtu 16384
      options=3&lt;RXCSUM,TXCSUM&gt;
      inet6 ::1 prefixlen 128 
      inet 127.0.0.1 netmask 0xff000000 
      inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
      nd6 options=1&lt;PERFORMNUD&gt;
  
  en1: flags=8863&lt;UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST&gt; mtu 1500
      ether .... 
      inet6 ....%en1 prefixlen 64 scopeid 0x5 
      inet 10.0.1.203 netmask 0xffffff00 broadcast 10.0.1.255
      nd6 options=1&lt;PERFORMNUD&gt;
      media: autoselect
      status: active
  </code></pre>