【问题标题】:Docker-compose and JavaDocker-compose 和 Java
【发布时间】:2021-02-08 16:19:55
【问题描述】:

我对 devops 世界很陌生,目前正在学习它。我正在尝试使用 kafka 和与其交互的特定应用程序启动一个 docker-compose 文件,遵循其中一个教程。它需要使用以下参数启动java jar:

java -Dcom.sun.management.jmxremote.port=5555 \
   -Dcom.sun.management.jmxremote.authenticate=false \
   -Dcom.sun.management.jmxremote.ssl=false \
   -jar build/libs/kafka-streams-scaling-all.jar

问题是 - 如何运行带有选项的多行命令?我试过这样:

autoscaling:
  exec:
    command:
    - java
    - |
    -Dcom.sun.management.jmxremote.port=5555 \
    -Dcom.sun.management.jmxremote.authenticate=false \
    -Dcom.sun.management.jmxremote.ssl=false \
    -jar build/libs/kafka-streams-scaling-all.jar

但它返回 in "./docker-compose.yml", line 75, column 9 could not find expected ':' in "./docker-compose.yml", line 76, column 9

还有网上的一些答案建议使用>号:

autoscaling:
  exec:
    command: >
      java -Dcom.sun.management.jmxremote.port=5555 \
      -Dcom.sun.management.jmxremote.authenticate=false \
      -Dcom.sun.management.jmxremote.ssl=false \
      -jar build/libs/kafka-streams-scaling-all.jar

但是docker好像没看懂命令expected <block end>, but found '-' in "./docker-compose.yml", line 74, column 7的“-”部分

使用 docker-compose 文件中的选项运行 java jar 的最佳方法是什么?

【问题讨论】:

    标签: java docker docker-compose jmx


    【解决方案1】:

    错误的缩进

    <service_name>:
        command: |
          java \
          -Dcom.sun.management.jmxremote.port=5555 \
          -Dcom.sun.management.jmxremote.authenticate=false \
          -Dcom.sun.management.jmxremote.ssl=false \
          -jar build/libs/kafka-streams-scaling-all.jar
    

    【讨论】:

    • 谢谢。所有的错误都消失了。但似乎这个问题比我想象的要复杂一些。它要求提供图像或 Dockerfile 来启动服务。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-11
    • 2015-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-16
    相关资源
    最近更新 更多