0

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
          }
        }'
Tahir Mustafa
  • 323
  • 1
  • 10
  • Could you post your docker compose yaml file? – sigur Jun 28 '22 at 14:53
  • 1
    The `-e ...` on your `docker run` command isn't setting an environment variable. It comes *after* the image name, so it's a command for the container. – Hans Kilian Jun 28 '22 at 15:01
  • @HansKilian can you suggest what's the replacement for it in docker-compose? In the docker documentation -e specified environment variable https://docs.docker.com/engine/reference/commandline/run/#:~:text=%2D%2Denv%20%2C%20%2De,Set%20environment%20variables – Tahir Mustafa Jun 28 '22 at 15:04
  • Take a look at https://stackoverflow.com/questions/53197806/how-to-get-proper-docker-compose-multiline-environment-variables-formatting . This question could be the possible duplicate of that one. – sigur Jun 28 '22 at 15:17

1 Answers1

1

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.

Hans Kilian
  • 18,948
  • 1
  • 26
  • 35