Filebeat.yml not recognized environment variable

Hello everyone, I am trying to obtain the logs generated by the console in a container that has a backend with the ECS format from the @elastic/ecs-winston-format library, with a filebeat service. However, it does not recognize the environment variables specified in the service definition, so for it to connect correctly I have to literally pass the address. I leave you my current configuration hoping someone can help me. Thank you very much in advance

docker-compose.yml file

version: '3.9'

services:
  node_microservice:
    container_name: node_bff_microservice
    image: node_microservice
    restart: always
    build:
      context: .
      dockerfile: Dockerfile
    environment:
      - ENV=local:docker
      - HOST=0.0.0.0
      - PORT=3336
    ports:
      - '3336:3336'
    networks:
      - elk
    labels:
      co.elastic.logs/json.overwrite_keys: 'true'
      co.elastic.logs/json.add_error_key: 'true'
      co.elastic.logs/json.expand_keys: 'true'
  filebeat:
    container_name: filebeat
    image: docker.elastic.co/beats/filebeat:8.11.3
    user: root
    command: >
      --strict.perms=false -e
      -E output.elasticsearch.hosts=elasticsearch:9400
    volumes:
      - ./filebeat.yml:/usr/share/filebeat/filebeat.yml:ro
      - /var/lib/docker/containers:/var/lib/docker/containers:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
    environment:
      - ELASTICSEARCH_HOST=elasticsearch:9200
      - KIBANA_HOST=kibana:5601
      - ELASTICSEARCH_USERNAME=elastic
      - ELASTICSEARCH_PASSWORD=change
    networks:
      - elk


networks:
  elk:
    external: true

filebeat.yml

filebeat.config:
  modules:
    path: ${path.config}/modules.d/*.yml
    reload.enabled: false


filebeat.autodiscover:
  providers:
    - type: docker
      hints.enabled: true


processors:
  - add_cloud_metadata: ~
  - add_docker_metadata: ~
  - add_host_metadata: ~


setup.kibana:
  host: "${ KIBANA_HOST:kibana:5601 }"

output.elasticsearch:
  hosts: "${ ELASTICSEARCH_HOST:elasticsearch:9200 }".  => If I remove the default value it doesn't work
  #username: ${ELASTICSEARCH_USERNAME}
  #password: ${ELASTICSEARCH_PASSWORD}

Hi @Alejandro_Avila_Pere Welcome to the community.

Silly question why do have that leading space?

${ ELASTICSEARCH_HOST
..^

1 Like

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