最近想学习下java GC优化,就用了一下VisualVM,在远程服务器启动了一个非docker的tomcat,很顺利的就连接了,但是用docker-compose启动的服务却

怎么也连不上,一定是docker的锅.

最终找到了解决方法,在这里 https://forums.docker.com/t/enable-jmx-rmi-access-to-a-docker-container/625

这篇文章中最重要的一句话就是

In my case, I am working with docker-compose please DON FORGET to expose the SAME PORT 6001 in the remote docker host (it won't work if you expose in another port differently that jmxremote.port and jmxremote.rmi.port):

一句话概括就是: docker-compose暴露的端口要跟jmx的端口一样

好了,问题解决,下面写出tomcat配置jmx的方法:

1. docker-compose.yml

web:
image: "registry.xxxxxx.com/msgbox/base_tomcat:tomcat7.42_jdk8u40"
ports:
- :
- :
- :
volumes:
- ./confs:/data1/confs
- ./web/webapps:/data1/xxx/webapps
- ./authconfs:/data1/authconfs
- ./web/logs:/data1/xxx/logs
environment:
- NAME_CONF=test-yf=/data1/xxx/bin/./
- RUN_COMMAND=catalina.sh jpda run
- JMX_PORT=
- JMX_HOST=10.77.6.164
- CATALINA_HEAP=-server -Xmx768m -Xmn100m -Xms768m
links:
- kafka

2. setenv.sh

if [[ ! -z "$JMX_PORT" ]]; then
if [ -z "$JMX_HOST" ]; then
JMX_HOST=$(hostname -i)
fi
CATALINA_EXTRA="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=${JMX_PORT} -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file=../conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=../conf/jmxremote.access -Djava.rmi.server.hostname=${JMX_HOST} -Dcom.sun.management.jmxremote.rmi.port=${JMX_PORT}"
fi

完成

最新文章

  1. zepto.js学习
  2. [python实现设计模式]-5.迭代器模式-一起撸串嗨皮啦
  3. 使用ADO.NET执行SQL脚本
  4. json返回数据库的时间格式为/Date(1477294037000)/,怎样在前台进行格式化转换
  5. css问题 ie7兼容性问题
  6. HDU4057 Rescue the Rabbit(AC自动机+状压DP)
  7. API 双方认证探讨
  8. char[] 操作
  9. C#调用WORD处理的实例代码(包含excel)
  10. 24种设计模式--单例模式【Singleton Pattern】
  11. MegaCLI SAS RAID Management Tool
  12. FileUpload的使用案例
  13. java 缓存ehcache的使用(使用方式一)
  14. 2272: [Usaco2011 Feb]Cowlphabet 奶牛文字
  15. 01Vue数据双向绑定
  16. 解决IIS无法启动w3svc
  17. js中escape对应的C#解码函数 UrlDecode
  18. 如何使用thinkphp的model来验证前端表单?
  19. 2017青岛赛区网络赛 Smallest Minimum Cut 求最小割的最小割边数
  20. [UE4]Canvas Panel应用小技巧

热门文章

  1. Linux(四)__javaee开发环境的搭建
  2. Storm的ack机制在项目应用中的坑
  3. CSS3媒体查询使用小结
  4. 修改NavigationBarItem的字体大小和颜色的使用方法
  5. IOS开发基础知识--碎片24
  6. c#中抽象类(abstract)和接口(interface)的相同点与区别
  7. Maven之 聚合与继承 详解
  8. 权重最小生成树的思想与Kruskal算法
  9. Linux命令学习总结:cp命令
  10. AsyncTask官方学习