Duš*_*lay 3 java jvm-arguments maven-plugin docker spring-boot
我正在使用spring-boot-maven-plugin通过以下命令从我的应用程序构建 docker 映像:
spring-boot::build-image
Run Code Online (Sandbox Code Playgroud)
我需要使用以下 jvm 参数更改 jvm 直接内存的默认大小(默认为 10m):
-XX:MaxDirectMemorySize=64M
Run Code Online (Sandbox Code Playgroud)
这是我绝望地尝试在应用程序中做到这一点pom.xml,我尝试了我想到的一切:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<configuration>
<jvmArguments>-XX:MaxDirectMemorySize=64M</jvmArguments>
<environmentVariables>
<JAVA_TOOL_OPTIONS>-XX:MaxDirectMemorySize=64M</JAVA_TOOL_OPTIONS>
<JAVA_OPTS>-XX:MaxDirectMemorySize=64M</JAVA_OPTS>
</environmentVariables>
<systemPropertyVariables>
<JAVA_TOOL_OPTIONS>-XX:MaxDirectMemorySize=64M</JAVA_TOOL_OPTIONS>
<JAVA_OPTS>-XX:MaxDirectMemorySize=64M</JAVA_OPTS>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
<configuration>
<layers>
<enabled>true</enabled>
</layers>
<image>
<name>docker.io/example/${project.artifactId}:${project.version}</name>
</image>
<excludeDevtools>true</excludeDevtools>
<systemPropertyVariables>
<JAVA_TOOL_OPTIONS>-XX:MaxDirectMemorySize=64M</JAVA_TOOL_OPTIONS>
<JAVA_OPTS>-XX:MaxDirectMemorySize=64M</JAVA_OPTS>
</systemPropertyVariables>
<environmentVariables>
<JAVA_TOOL_OPTIONS>-XX:MaxDirectMemorySize=64M</JAVA_TOOL_OPTIONS>
<JAVA_OPTS>-XX:MaxDirectMemorySize=64M</JAVA_OPTS>
</environmentVariables>
<jvmArguments>-XX:MaxDirectMemorySize=64M -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005</jvmArguments>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
但直接内存仍设置为 10M :( 应用程序启动时我可以在日志文件中看到:
Picked up JAVA_TOOL_OPTIONS: -Djava.security.properties=/layers/paketo-buildpacks_bellsoft-liberica/java-security-properties/java-security.properties -agentpath:/layers/paketo-buildpacks_bellsoft-liberica/jvmkill/jvmkill-1.16.0-RELEASE.so=printHeapHistogram=1 -XX:ActiveProcessorCount=8 -XX:MaxDirectMemorySize=10M -Xmx11521920K -XX:MaxMetaspaceSize=144375K -XX:ReservedCodeCacheSize=240M -Xss1M -Dorg.springframework.cloud.bindings.boot.enable=true
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我我做错了什么吗?
笔记:
Spring Boot:2.3.7.RELEASE
当我使用 手动运行 docker image 时-e,jvm 参数的更改正在起作用:
docker run -e JAVA_TOOL_OPTIONS=-XX:MaxDirectMemorySize=64M docker.io/example/app-name:0.0.1
Run Code Online (Sandbox Code Playgroud)
这个 mvn 插件使用 Buildpack 来创建 docker 镜像:
https://paketo.io/docs/buildpacks/language-family-buildpacks/java/#about-the-jvm
更新:
根据文档,这应该是可行的解决方案,但事实并非如此:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layers>
<enabled>true</enabled>
</layers>
<image>
<name>docker.io/example/${project.artifactId}:${project.version}</name>
<env>
<JAVA_TOOL_OPTIONS>-XX:MaxDirectMemorySize=64M</JAVA_TOOL_OPTIONS>
</env>
</image>
</configuration>
Run Code Online (Sandbox Code Playgroud)
这是关于如何使运行时环境“粘性”的有效解决方案:
....
<image>
<name>docker.io/example/${project.artifactId}:${project.version}</name>
<env>
<BPE_APPEND_JAVA_TOOL_OPTIONS>-XX:MaxDirectMemorySize=64M</BPE_APPEND_JAVA_TOOL_OPTIONS>
<BPE_DELIM_JAVA_TOOL_OPTIONS xml:space="preserve"> </BPE_DELIM_JAVA_TOOL_OPTIONS>
</env>
</image>
...
Run Code Online (Sandbox Code Playgroud)
spring-boot-maven-plugin 使用 paketo 构建包:
文档: https: //github.com/paketo-buildpacks/environment-variables
| 归档时间: |
|
| 查看次数: |
2784 次 |
| 最近记录: |