在 DOCKERFILE 中运行 2 个 java 进程

问题描述

我在 kuberntes 中有一个 ignite(gridgain-community) statefulset 集群。 我从下面的 docker(cmd 运行 jmx 导出器)创建了 sucssfuly 图像:

FROM gridgain/community:8.8.1-slim

USER root
RUN mkdir -p /opt/jmx_exporter/

copY ./jmx/*  /opt/jmx_exporter/
RUN chmod 700 /opt/jmx_exporter/start.sh
CMD ["/bin/sh","/opt/jmx_exporter/start.sh"]

但是当我从此图像开始图表时,pod 正在运行但尚未准备好:

NAME          READY   STATUS    RESTARTS   AGE
online-db-0   0/1     Running   3          4m2s

并在描述中:

  normal   Started    51s                kubelet,samppc01srv01kbr002.novalocal  Started container online-db
  Warning  Unhealthy  12s (x3 over 32s)  kubelet,samppc01srv01kbr002.novalocal  Liveness probe Failed: Get http://10.233.109.23:8080/ignite?cmd=version: dial tcp 10.233.109.23:8080: connect: connection refused
  normal   Killing    12s                kubelet,samppc01srv01kbr002.novalocal  Container online-db Failed liveness probe,will be restarted
  Warning  Unhealthy  9s (x3 over 29s)   kubelet,samppc01srv01kbr002.novalocal  Readiness probe Failed: Get http://<IP>/ignite?cmd=probe: dial tcp <ip>:8080: connect: connection refused

当我检查 pod 时,我看到只有 jmx 启动而 ignite java 关闭,当我在 ignite 容器上手动启动 jmx 时它确实起作用了:

bash-4.4# ps -ef | grep java
    6 root      0:01 java -Djava.net.preferIPv4Stack=true -jar /opt/jmx_exporter/jmx_prometheus_httpserver-0.12.0-jar-with-dependencies.jar 5556 /opt/jmx_exporter/config.yml
   26 root      0:00 grep java

start.sh - java_script

!/bin/sh

if [ -z "$SERVICE_PORT" ]; then
 

     SERVICE_PORT=5556
    fi
    
    if [ -z "$JVM_OPTS" ]; then
      JVM_OPTS="-Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=5555"
    fi
    
    if [ -z "$CONfig_YML" ]; then
      CONfig_YML=/opt/jmx_exporter/config.yml
    fi
    
    VERSION=0.12.0
    
    java $JVM_OPTS -jar /opt/jmx_exporter/jmx_prometheus_httpserver-$VERSION-jar-with-dependencies.jar $SERVICE_PORT $CONfig_YML

日志中没有任何内容,有人可以帮助解释为什么会发生这种情况吗?

解决方法

我创建了一个 startall.sh 脚本,它同时运行 ignite 进程和 jm scrpts,如下所示:

#!/bin/sh

set -m


/opt/jmx_exporter/start.sh &

/bin/sh -c ${IGNITE_HOME}/run.sh

然后编辑我的 dockefile 以仅运行包装器脚本:

FROM gridgain/community:8.8.1-slim
USER root
RUN mkdir -p /opt/jmx_exporter/ 
COPY ./jmx/*  /opt/jmx_exporter/ 
RUN chmod 700 /opt/jmx_exporter/start.sh 
CMD ["/bin/sh","/opt/jmx_exporter/startall.sh" ]

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...