liveBook · Manning

Fluentd

As explained in Learn Docker in a Month of Lunches, Second Edition

Fluentd is an open-source unified logging layer that collects, processes, enriches, filters, and forwards log data.

When logs come from many containers, Fluentd can collect them in one place. It ingests log records, filters or enriches them, and forwards them to a destination. Docker containers can send logs through the built-in Fluentd logging driver; Fluentd can also read logs from Docker’s JSON files. section 19.3

cd ch19/exercises/fluentd
# run Fluentd publishing the standard port and using a config file:
docker run -d -p 24224:24224 `
 --name fluentd -v "$(pwd)/conf:/fluentd/etc" `
 -e FLUENTD_CONF=stdout.conf `
 diamol/fluentd:2e
# now run a timecheck container set to use Docker's Fluentd log driver:
docker run -d --log-driver=fluentd `
 --name timecheck5 `
 diamol/ch19-timecheck:2e-v3
# check the timecheck container logs:
docker logs timecheck5
# and check the Fluentd container logs:
docker logs --tail 1 fluentd

Run Fluentd with a configuration that writes received records to stdout, then start a container with `--log-driver=fluentd`. Compare `docker logs timecheck5` with the Fluentd container’s logs to verify forwarding. Fluentd adds the source container’s ID and name to each record. section 19.3

For searchable, centralized logs, Fluentd can forward records to Elasticsearch, where Kibana provides a search interface. Application logs must first be visible as container logs: write them to stdout directly or relay them there. This keeps the destination out of application code, so the logging stack can change without reworking each app. section 19.3 section 19.5

Listing 19.4 Sending log entries to different targets based on the tag
<match gallery.access-log.**>
  @type copy
  <store>
    @type stdout
  </store>
</match>
<match gallery.**>
  @type copy
  <store>
    @type elasticsearch
. . .

Match blocks route records by the tag set in Docker’s logging options. Here, access-log records go to Fluentd’s stdout, while other gallery records go to Elasticsearch. The configuration can also split a tag into app, service, and image fields for easier filtering in Kibana. section 19.4

Practice: configure another application

Set the Fluentd logging driver and an app–service–image tag on every component of the numbers app. Configure Fluentd to split that tag into fields, and send records from other apps to stdout as a failsafe. section 19.6

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Works through driver setup and tag-based routing, but leaves fuller Fluentd configuration practice to a lab.
Examples
Uses a timecheck container for forwarding, an image gallery for filtering, and a numbers app for practice.
What it assumes
Assumes familiarity with running Docker containers and editing Compose configuration; introduces Fluentd through a simple stdout setup.
What you can do after
Operate/configure it to route tagged container logs and enrich records without changing application images.
How it connects
Connects Docker container logs and logging drivers with Elasticsearch, Kibana, stdout, and Docker Compose.

Also explained in

Compare how 4 books explain fluentd →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.