1

I try to run services (mongo) in swarm mode with log collected to elasticsearch via fluentd. It's worked(!) with:

docker-compose up

But when I deploy via stack, services started, but logs not collected, and i don't know how to see what the reason.

docker stack deploy -c docker-compose.yml env_staging

docker-compose.yml:

version: "3"
services:
    mongo:
        image: mongo:3.6.3
        depends_on:
         - fluentd
        command: mongod
        networks:
         - webnet
        logging:
          driver: "fluentd"
          options:
            fluentd-address: localhost:24224
            tag: mongo
    fluentd:
        image: zella/fluentd-es
        depends_on:
         - elasticsearch
        ports:
         - 24224:24224
         - 24224:24224/udp
        networks:
         - webnet
    elasticsearch:
        image: elasticsearch
        ports:
         - 9200:9200
        networks:
         - webnet
    kibana:
        image: kibana
        depends_on:
         - elasticsearch
        ports:
         - 5601:5601
        networks:
         - webnet
networks:
     webnet:

upd

I remove fluentd-address: localhost:24224 and problem solves. But I don't understand what is "localhost"? Why we can't set "fluentd" host. If someone explain what is fluentd-address, I will accept answer.

zella
  • 4,645
  • 6
  • 35
  • 60

2 Answers2

0

fluentd-address is the address where fluentd daemon resides (default is localhost and you don't need to specify it in this case).

In your case (using stack) your fluentd daemon will run on a node, you should reach that service using the name of the service (in your case fluentd, have you tried?).

Remember to add to your options the fluentd-async-connect: "true"

Reference is at: https://docs.docker.com/config/containers/logging/fluentd/#usage

Nicola Ben
  • 10,615
  • 8
  • 41
  • 65
  • 1
    I tried several times with `fluentd-address: localhost:24224` and `fluentd-address: fluentd:24224`. with "localhost" service fail to start. When I use "fluentd" host there are no logs in es. Only without this lines it's working. So i not sure, that "localhost" is default value – zella May 14 '18 at 19:01
  • inside your webnet, can you ping fluentd? Do you receive a response? – Nicola Ben May 14 '18 at 19:39
  • I found answer here https://stackoverflow.com/questions/45346005/cant-log-from-fluentd-logdriver-using-service-name-in-compose And default host 127.0.0.1 which works – zella May 14 '18 at 20:28
0

You don't need to specify fluentd-address. When you set logging driver to fluentd, Swarm automatically discovers nearest fluentd instance and sends there all stdout of desired container.

Bluesboy
  • 51
  • 2
  • 2