简体   繁体   中英

cannot connect to jmx jar process in docker container through jconsole

I am trying to retrieve metrics from a java process that is running in a docker container. The process was started with the following command but trying to access it via jconsole as a test, results in 'connection failed' retry?

docker run -d --name=process-2-kafka --restart=always -p 22222:22222 -v 
/var/local/Blogs_Services/ProcessKafaka/:/program -w /program openjdk:8 
java
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=22222 - 
Dcom.sun.management.jmxremote.ssl=false - 
Dcom.sun.management.jmxremote.authenticate=false -jar testkafka.jar - 
Dcom.sun.management.jmxremote.local.only=false – 
Djava.rmi.server.hostname=192.www.xxx.yy – 
Dcom.sun.management.jmxremote.rmi.port=22222

I added the rmi.port and server.hostname after searching the internet but still results in the same error. Does anyone have a solution to this?

JMX connections to containers are notoriously frustrating. Two things I would suggest to try:

  1. Use a separate port for jmxremote.port and jmxremote.rmi.port (for example 22222 and 22223) and port forward both of these in docker

  2. Set your java.rmi.server.hostname to be a name, eg dockerhost , and add dockerhost and the IP address of the machine hosting the container to your hosts file on all of the machine running the docker container, the docker container itself, and the machine you are running jconsole on. Then when you try to JMX, use dockerhost in the URL instead of an IP address.

These may not solve your problem, but fingers crossed, good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM