How to access JMX (Java Beans) from a process running in docker container

Why is it so hard to connect to a JMX port (using JConsole), when a process is run using Docker.

Of course I have exposed the JMX port to the host, and even used Sun specific options while running the Java process (following the instructions from http://ptmccarthy.github.io/2014/07/24/remote-jmx-with-docker/ ).

  • What are the advantages of running jenkins in a docker container
  • Is it possible to directly call docker run from AWS lambda
  • Segmentation Fault (core dumped) while running phpunit
  • Docker: Unable to run shell script stored in a mounted volume
  • How to run a Shiny docker container on Alpine Linux?
  • Docker image for project with separate client and server side codebase
  • I am able to telnet to the host ip and the exposed JMX port, which tells that it is accessible. But I can’t figure out a way to use JConsole and connect to the JMX service running in the container.

    -Djava.rmi.server.hostname=$JMX_HOSTNAME
    -Dcom.sun.management.jmxremote.port=$JMX_PORT
    -Dcom.sun.management.jmxremote.rmi.port=$JMX_PORT
    

  • Microservices and Dockerfile and docker-compose.yml
  • celery pdb running inside docker container with changing listening port
  • How could one use Docker Compose to synchronize container execution?
  • How can I use an environment variable as a name for a docker container?
  • can't connect to docker container from outside
  • Docker: how to update changes in php.ini inside of container
  • 3 Solutions collect form web for “How to access JMX (Java Beans) from a process running in docker container”

    In the past, the two ports had to be different. Please try that for a start.

    If thats not working:

    Tomcat offers an additional component to set the second port mentioned, the JMX Remote Lifecycle Listener.

    Please have a look at:

    http://tomcat.apache.org/tomcat-7.0-doc/extras.html

    http://tomcat.apache.org/download-70.cgi

    I´m using this setting with catalina-jmx-remote.jar in my tomcat/lib directory to get through:

    -Dcom.sun.management.jmxremote 
    -Dcom.sun.management.jmxremote.ssl=false 
    -Djava.rmi.server.hostname=localhost
    -DrmiRegistryPortPlatform=10381 
    -DrmiServerPortPlatform=10380
    

    Plus these, but you wouldn´t need them in a dev environment.

    -Dcom.sun.management.jmxremote.password.file=/home/tomcat/jmxremote.password 
    -Dcom.sun.management.jmxremote.access.file=/home/tomcat/jmxremote.access 
    -Dcom.sun.management.jmxremote.authenticate=true
    

    What you currently have looks correct. To at least try and get it working, i’d try disabling auth & ssl. Then, once you get it working, think about re-enabling any security you require:

    -Dcom.sun.management.jmxremote.authenticate=false
    -Dcom.sun.management.jmxremote.ssl=false
    

    Indeed, you need those 2 ports to be different. One port is for the RMI registry and the other for the remoting protocol.

    When specifying the URL to connect to the server from jconsole/visualvm use the port set in “-Dcom.sun.management.jmxremote.port” on the server side.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.