Home > Software design >  How to pass multiline environment variable in docker-compose.yml
How to pass multiline environment variable in docker-compose.yml

Time:06-29

I am trying to convert this "opensearch-logstash-docker-%{+YYYY.MM.dd}" user => "admin" password => "admin" ssl => true ssl_certificate_verification => false } }'" rel="nofollow noreferrer">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
          }
        }'

CodePudding user response:

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.

  • Related