Problem connection LogStash to ElasticSearch in DockerCompose

Hi everyone,
I am currently developing a little project for university essay with educational purposes.
In this project, I'm trying to use rabbit mq to send Log messages to Logstash from a Spring Boot Backend. Currently, the Logstash container Logs indicate error when resolving the ES service.

[2022-12-08T11:11:12,649][WARN ][logstash.licensechecker.licensereader] Attempted to resurrect connection to dead ES instance, but got an error {:url=>"http://localhost:9200/", :exception=>LogStash::Outputs::Elasticsearch::HttpClient::Pool::HostUnreachableError, :message=>"Elasticsearch Unreachable: [http://localhost:9200/][Manticore::SocketException] Connect to localhost:9200 [localhost/127.0.0.1] failed: Connection refused"}

In no place I say that the ES is running on localhost, and before using Rabbit MQ the same output worked from a TCP input from the Spring Boot backend.
Here is my LogStash conf file:

input {
  rabbitmq {
    subscription_retry_interval_seconds => 2
    automatic_recovery => true
    connect_retry_interval => 3
    durable => true   
    exchange => "EnterpriseApplicationLog" 
    exchange_type => "topic"
    key => ""
    host => "rabbitmq"
    vhost => "/"
    queue => "ApplicationLog"
    port => 5672	
    user => "guest"
    password => "guest"    
    passive => false
    prefetch_count => 10
    threads => 1
    ack => true
    # type => "Log"
  }  
}
 
output {
  elasticsearch {
    action => "index"
    codec => "json"
    hosts => ["elasticsearch"]
    index => "logstash-%{+YYYY.MM.dd}"
  }
}

DockerCompose file:

version: "3"
services:
  db:
    image: postgres:15.1-alpine
    restart: always
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
    ports:
      - '5432:5432'
    volumes: 
      - ./db-data:/var/lib/postgresql/data
          # copy the sql script to create tables
      - ./bd.sql:/docker-entrypoint-initdb.d/create_tables.sql
    networks:
        - appreservas
  rabbitmq:
    image: rabbitmq:3-management-alpine
    container_name: 'rabbitmq'
    ports:
        - 5672:5672
        - 15672:15672
    volumes:
        - ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/
        - ~/.docker-conf/rabbitmq/log/:/var/log/rabbitmq
    networks:
        - appreservas
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.5.2
    container_name: elasticsearch_springboot
    environment:
        - bootstrap.memory_lock=true
        - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        - "discovery.type=single-node"
        - xpack.security.enabled=false
    ports:
        - "9200:9200"
    volumes:
        - elasticsearch_data:/usr/share/elasticsearch/data
    networks:
        - appreservas
  kibana:
    image: docker.elastic.co/kibana/kibana:8.5.2
    container_name: kibana_springboot
    ports:
        - "5601:5601"
    environment:
        ELASTICSEARCH_URL: http://elasticsearch:9200
        ELASTICSEARCH_HOSTS: '["http://elasticsearch:9200"]'
    depends_on:
        - elasticsearch
    networks:
        - appreservas
  logstash:
    image: docker.elastic.co/logstash/logstash:8.5.2
    container_name: logstash_springboot
    volumes:
      - ./logstash/config/logstash.yml:/usr/share/logstash/config/logstash.yml:ro
      - ./logstash/pipeline:/usr/share/logstash/pipeline:ro
    ports:
      - "5044:5044"
      - "5000:5000/tcp"
      - "5000:5000/udp"
      - "9600:9600"
    environment:
      LS_JAVA_OPTS: "-Xmx256m -Xms256m"
      RABBIT_MQ_IP: "rabbitmq"
    networks:
      - appreservas
    depends_on:
      - elasticsearch
      - rabbitmq
  auth-backend: 
    build: 
      context: ./auth
    ports: 
      - '8085:8085'
    environment:
      - SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/appreservas?currentSchema=auth
      - LOGSTASH_URL=logstash:5000
      - RABBIT_MQ_IP=rabbitmq
    depends_on:
      - db
      - logstash
      - rabbitmq
    networks:
      - appreservas
volumes:  
  db:
    driver: local
  elasticsearch_data:
    driver: local
  elastic_data: {}
networks:
  appreservas:

Thanks in advance!

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