Logstash container gets closed automatically after installation of the "logstash-input-mongodb" plugin

Hi everyone, I'm trying to run the Logstash container in the docker-compose file to sync my MongoDB data with Elastic. But, after the step of installation of the "logstash-input-MongoDB" plugin, the container gets exited for some reason. Any help would be appreciated.

docker-compose.yml

  logstash:
      image: docker.elastic.co/logstash/logstash:7.17.16
      container_name: logstash
      volumes:
        - ./logstash/pipeline/logstash.conf:/usr/share/logstash/pipeline/logstash.conf
      ports:
        - '9600:9600'
      depends_on:
        - elastic
        - database
      networks:
        - appnet
      command: bin/logstash-plugin install logstash-input-mongodb && bin/logstash -f /usr/share/logstash/pipeline/logstash.conf

logstash.conf

input {
  mongodb {
    uri => 'mongodb://mongo_host:27017/mydatabase'
    placeholder_db_dir => '/opt/logstash-mongodb/'
    placeholder_db_name => 'logstash_sqlite_devices.db'
    collection => 'devices'
    batch_size => 5000
  }

  mongodb {
    uri => 'mongodb://mongo_host:27017/mydatabase'
    placeholder_db_dir => '/opt/logstash-mongodb/'
    placeholder_db_name => 'logstash_sqlite_vendors.db'
    collection => 'vendors'
    batch_size => 5000
  }
}

filter {
  mutate {
    remove_field => ["_id"]
  }
}

output {
  elasticsearch {
    hosts => ['elastic:9200']
    index => "%{[@metadata][index]}"
  }
}

&& is a function provided by a shell. Can you try something like: command: bash -c "bin/logstash-plugin install logstash-input-mongodb && bin/logstash -f /usr/share/logstash/pipeline/logstash.conf logstash.conf"

Note: I have not tested this command and I have written it freehand

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.