How to connect with JMX from host to Docker container in Docker machine?

How to connect with JMX from host to Docker container in Docker machine?

When I have running Docker container directly at my host, it is possible to connect to it without any problems.
My host has network and IP address of the host is My Docker container has IP address When I connect to from jconsole it works.
When I put this service into Docker machine, it is not possible to connect to it.
My Docker machine has IP and container in it has IP address but when I use jconsole to connect to it does not work.
To repeat it: — works — ( — and connecting to from my host does not work.
It is worth to say that I can access services containerized in Docker machine via external IP address of the Docker machine, e.g. this will work: — ( —
But when I use JMX it just does not work.
It is Tomcat service. I have this in scripts which starts Tomcat instance:
CATALINA_OPTS=”-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n \ \ \ \ \
-Djava.rmi.server.hostname=IP address of Docker container


Solution 1:

I think the problem is probably the value of the java.rmi.server.hostname property. This needs to be the hostname or IP address that should be used by the JMX client to connect to your JVM. That is in the first case where you connect to your container directly using, this setting needs to be set to In the latter case where you access the container through the docker machine on, the setting needs to be set to

During my research for a very similar question (which was deleted in the meantime) I stumbled across a blog entry (which was deleted in the meantime as well). Although It’s rather old it gave me an idea how the JMX connectivity works:

  1. The JMX registry listens on port <> of the container
  2. If you connect to the registry with JConsole, the registry provides the JMX service URL to the client.
  3. This URL is used by the client to obtain the JMX objects
Related:  Vagrant and Docker not playing nice

The service URL looks like this service:jmx:rmi:///jndi/rmi://<java.rmi.server.hostname>:<>/jmxrmi. That is in your case service:jmx:rmi:///jndi/rmi:// As this address is only reachable from within the docker machine, connecting from remote is not possible. In my question I cover the same problem in regards to the RMI port…

There doesn’t seem to be an out-of-the-box solution to this problem. However one can provide both JMX port and the external hostname (or IP) on startup of the container as environment variables, as suggested here. These could then be used in the JMX config:

docker run -p 1099:1099 \
    -e "JMX_HOST=" \
    -e "JMX_PORT=1099" \



Not very nice, but it should work…

Solution 2:

If anyone has problems with it. I have started the java process in the docker container with the following parameters: 
-Djava.rmi.server.hostname=<name of the docker container>

The important part is to set the name of the docker container. EXPOSE the port in the container 9876. I have also setup an ssh connection and forwarded 9876 to the localhost.

The following goes to your SSH config:


Also I have setup /etc/hosts on the local machine <name of the docker container>

Now connect your console to “name of the docker container”