Docker-compose在JAVA_OPTS上看不到环境变量

时间:2019-07-02 13:22:27

标签: docker cassandra docker-compose

我正在尝试设置JAVA_OPTS变量以使用docker-compose运行elassandra。

这是我所实施的:

docker-compose.yml

version: '2'
services:
 elassandra:
    image: strapdata/elassandra:new
    container_name: elassandra
    environment:
      - echo 'JVM_OPTS="$JVM_OPTS -javaagent:/var/lib/docker/volumes/data/_data/jmx_prometheus_javaagent-0.3.0.jar=6090:/var/lib/docker/volumes/data/_data/cassandra.yml"' >> /etc/cassandra/cassandra-env.sh
    env_file:
      - /home/ubuntu/Docker/cassandra/conf/cassandra.env
    volumes:
       - /home/ubuntu/Docker/cassandra/jarfile:/var/lib/docker/volumes/data/_data
    ports:
      - '7000:7000'
      - '7001:7001'
      - '7199:7199'
      - '9042:9042'
      - '9142:9142'
      - '9160:9160'
      - '9200:9200'

Volume和env_files正常工作,唯一的问题是docker-compose没有看到环境变量,并且在运行docker-compose -f docker-compose.yml up命令后,我遇到了以下错误,该错误导致elassandra停止工作:

The JVM_OPTS variable is not set. Defaulting to a blank string.
  

我还尝试了argcommand而不是environment,不幸的是,它们都没有设置JAVA_OPTS变量。

问题:是否可以在docker-compose.yml文件中设置echo 'JVM_OPTS="$JVM_OPTS -javaagent:/var/lib/docker/volumes/data/_data/jmx_prometheus_javaagent-0.3.0.jar=6090:/var/lib/docker/volumes/data/_data/cassandra.yml"' >> /etc/cassandra/cassandra-env.sh之类的JAVA_OPTS变量?

0 个答案:

没有答案