logstash 如何在docker-compose.yml中传递多行环境变量

hjzp0vay  于 2022-12-09  发布在  Logstash
关注(0)|答案(1)|浏览(167)

我正在尝试转换此Docker运行命令:

docker run -it --rm --name logstash --net test opensearchproject/logstash-oss-with-opensearch-output-plugin:7.16.2 -e 'input { stdin { } } output {
 opensearch {
   hosts => ["https://opensearch:9200"]
   index => "opensearch-logstash-docker-%{+YYYY.MM.dd}"
   user => "admin"
   password => "admin"
   ssl => true
   ssl_certificate_verification => false
   }
}'

到一个docker-compose.yml文件。但是我不知道如何定义上面传递的环境配置。关于如何传递无名的多行环境变量到一个docker-compose. yml文件,有什么建议吗?
我尝试了多个yaml多行格式,但我一直得到:
错误:环境变量名称'input { stdin { } } output { opensearch { hosts '不能包含空格。
docker-compose.yml:

version: '3'

services:
  logstash-producer:
    image: opensearchproject/logstash-oss-with-opensearch-output-plugin:7.16.2
    container_name: logstash-producer
    environment:
      - 'input { stdin { } } output {
          opensearch {
            hosts => ["https://opensearch:9200"]
            index => "opensearch-logstash-docker-%{+YYYY.MM.dd}"
            user => "admin"
            password => "admin"
            ssl => true
            ssl_certificate_verification => false
          }
        }'
vfh0ocws

vfh0ocws1#

由于-e位在映像名称之后,因此它是容器的命令。
我从来没有做过这个,我无法测试它,但试试这个

version: '3'

services:
  logstash-producer:
    image: opensearchproject/logstash-oss-with-opensearch-output-plugin:7.16.2
    container_name: logstash-producer
    command: |
        -e 'input { stdin { } } output {
        opensearch {
          hosts => ["https://opensearch:9200"]
          index => "opensearch-logstash-docker-%{+YYYY.MM.dd}"
          user => "admin"
          password => "admin"
          ssl => true
          ssl_certificate_verification => false
        }
      }'

如果这样做不起作用,我会尝试将所有命令放在一行中。

相关问题