简体   繁体   English

Docker:如何在运行 Z05B6053C41A2130AFD6FC3B158BDA4 时打印 jvm memory 信息

[英]Docker : how to print jvm memory informations when running docker logs

I ve a java spring-boot app based, running on Docker.我有一个基于 java spring-boot 的应用程序,在 Docker 上运行。

Within my dockerfile , i'm using Entrypoint .在我的dockerfile中,我使用的是Entrypoint

Obviously, i ve used it like this:显然,我是这样使用它的:

ENTRYPOINT ["java","-Dfile.encoding=utf-8", "-XX:+ExitOnOutOfMemoryError","-Xms256m","-Xmx256m", "-XshowSettings:vm","-jar","/opt/myapp.jar", "--spring.profiles.active=server"]

Like this, when the container starts: it displays this such values when running docker logs :像这样,当容器启动时:它在运行docker logs时显示这样的值:

VM settings:
    Min. Heap Size: 256.00M
    Max. Heap Size: 256.00M
    Ergonomics Machine Class: client
    Using VM: OpenJDK 64-Bit Server VM


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.3.0.RELEASE)

But with a little transformation the the entrypoint format (to inject some en vars):但是通过一点点转换入口点格式(注入一些 en vars):

ENTRYPOINT java -jar /opt/myapp.jar -Dfile.encoding=utf-8 -XX:+ExitOnOutOfMemoryError -Xms=${XMS_VALUE} -Xmx=${XMX_VALUE} -XshowSettings:vm -XX:+PrintFlagsFinal --spring.profiles.active=server

That hides the jvm values, and displays only spring chart:这隐藏了 jvm 值,仅显示 spring 图表:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.3.2.RELEASE)

How may i let it appear again??我怎么能让它再次出现?

The order of JVM options and arguments is important. JVM选项和 arguments 的顺序很重要。 Usage is:用法是:

 java [options] -jar <jarfile> [args...]
           (to execute a jar file)

therefore the JVM options must be placed before the -jar option otherwise they are considered application arguments因此JVM选项必须放在-jar选项之前,否则它们被视为应用程序 arguments

ENTRYPOINT java -Dfile.encoding=utf-8 -XX:+ExitOnOutOfMemoryError \
    -Xms${XMS_VALUE} -Xmx${XMX_VALUE} \
    -XshowSettings:vm -XX:+PrintFlagsFinal -XshowSettings:vm \
    -jar /opt/myapp.jar --spring.profiles.active=server

Run it with:运行它:

docker run -e XMX_VALUE=256M -e XMS_VALUE=256m <image_name>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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