如何通过docker-compose.yml中多行环境变量

发布于 2025-02-11 07:19:28 字数 1883 浏览 1 评论 0原文

我正在尝试转换此 docker run命令

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文件。但是,我不知道如何定义上面传递的环境配置。关于如何将无名的多行环变量传递给码头组合的任何建议吗?

我尝试了多种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
          }
        }'

I am trying to convert this docker run command:

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
   }
}'

to a docker-compose.yml file. However I can't figure out how to define the environment config passed above. Any suggestions on how to pass nameless multiline environment variable to a docker-compose?

I tried multiple yaml multiline formats, but I keep getting:

ERROR: environment variable name 'input { stdin { } } output { opensearch { hosts ' may not
contain whitespace.

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
          }
        }'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三生池水覆流年 2025-02-18 07:19:29

由于-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
        }
      }'

如果那不起作用,请尝试将命令全部放在一行上。

Since the -e bit comes after the image name, it's a command for the container.

I've never done this and I'm unable to test it, but try this

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
        }
      }'

If that doesn't work, I'd try putting the command all on one line.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文