我需要使用像这样的JVM选项在Docker容器中运行Java应用程序,但是我不知道在哪里可以设置它,我已经尝试使用"java -Dcom...“。命令,但它不起作用。做这件事最好的方法是什么?
-Dcom.sun.management.jmxremote.rmi.port=9090
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=9090
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.local.only=false
-Djava.rmi.server.hostname=192.168.99.100
发布于 2018-07-30 19:04:00
下面是我给你的例子:
CMD java -Xmx1024m -Xms512m -Dserver.port=8080 -jar mywar.war
另外,如果您有很多属性要添加到这里,最好使用环境变量创建文件。并将它们装载到容器中。在你的应用程序中,使用环境变量来泛化你的应用程序。
发布于 2019-09-01 20:11:26
如果您正在使用docker-compose.yml文件运行,则应在特定docker条目下添加,例如:
docker-name:
extends:
file: ...
service: ...
image: ...
ports:
- "9090:9090"
environment:
component_type: ...
instance_id: ...
JAVA_OPTS: "
-Dcom.sun.management.jmxremote.rmi.port=9090
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=9090
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.local.only=false
-Djava.rmi.server.hostname=localhost"
volumes:
- ...
..
。。。。
发布于 2020-09-01 02:55:17
为了将JVM参数传递给Spring Boot应用程序,我使用了以下方法:
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.rmi.port=9010 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost"
我有一个docker-compose服务,使用类似VisualVM的东西来专门分析我的应用程序(看起来你也在尝试做一些类似的事情),因为我并不总是想使用这些配置:
version: '3.7'
services:
profile:
image: my_base_image
container_name: my_container_name
ports:
- '8081:8080'
- '9010:9010'
volumes:
- './src:/build/src
- './target:/build/target'
- './logs:/build/logs'
- './pom.xml:/build/pom.xml'
command: 'mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.rmi.port=9010 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost"'
我只是简单地运行以下命令来启动它:docker-compose up profile
如果你想阅读整篇文章,我已经写了这个主题:
https://blog.phillipninan.com/2020/08/19/diagnose-memory-leaks-in-spring-boot-with-visual-vm/
https://stackoverflow.com/questions/51592459
复制相似问题