services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.17.0
    container_name: elasticsearch
    environment:
      - node.name=elasticsearch
      - discovery.type=single-node
      - bootstrap.memory_lock=true
      - xpack.security.enabled=false
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - elasticsearch-data:/usr/share/elasticsearch/data
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://localhost:9200/_cluster/health?wait_for_status=yellow || exit 1"]
      interval: 10s
      timeout: 10s
      retries: 10
      start_period: 30s
    ports:
      - "9200:9200"
    networks:
      - elk

  kibana:
    image: docker.elastic.co/kibana/kibana:8.17.0
    container_name: kibana
    environment:
      - SERVER_HOST=0.0.0.0
      - ELASTICSEARCH_HOSTS=http://elasticsearch:9200
    volumes:
      - ../monitoring/elklogs/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml:ro   
    ports:
      - "5601:5601"
    networks:
      - elk
    depends_on:
      - elasticsearch

  logstash:
    image: docker.elastic.co/logstash/logstash:8.17.0
    container_name: logstash
    environment:
      - LS_JAVA_OPTS=-Xms512m -Xmx512m
    volumes:
      - ../monitoring/elklogs/logstash/pipeline/pipelines.yml:/usr/share/logstash/pipeline/pipelines.yml:ro
      - ../monitoring/elklogs/logstash/config/pipelines.yml:/usr/share/logstash/config/pipelines.yml:ro
      - ../monitoring/elklogs/logstash/config/jvm.options:/usr/share/logstash/config/jvm.options:ro   
    ports:
      - "5044:5044"
    networks:
      - elk
    depends_on:
      elasticsearch:
          condition: service_healthy
      
  filebeat:
    image: docker.elastic.co/beats/filebeat:8.17.0
    container_name: filebeat
    user: root
    command: filebeat -e --strict.perms=false
    volumes:
      - /var/lib/docker/containers:/var/lib/docker/containers:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ../monitoring/elklogs/filebeat/filebeat.yml:/usr/share/filebeat/filebeat.yml:ro   
    networks:
      - elk
    depends_on:
      - elasticsearch   

volumes:
  elasticsearch-data:
    driver: local

networks:
  elk:
    driver: bridge   