---
title: "Docker and Fluent Forward"
description: "Route container logs through Docker's fluentd driver, Fluentd or Fluent Bit into Logbrook."
---

> Documentation Index
> Fetch the complete documentation index at: https://sandrinodm.github.io/logbrook/llms.txt
> Use this file to discover all available pages before exploring further.

# Docker and Fluent Forward

Logbrook can receive logs over the [Forward protocol v1](https://github.com/fluent/fluentd/wiki/Forward-Protocol-Specification-v1). Docker's built-in `fluentd` logging driver, Fluentd and Fluent Bit can then send logs with no change to your applications. To set it up, enable the listener, route a tag to an index and point containers at it.

The receiver runs in the same `logbrook serve` process as the HTTP API. It is off by default and configured only in TOML. For every setting, see the [Forward listener reference](https://sandrinodm.github.io/logbrook/configure/forward-listener/).

## Enable the listener

Merge this into your server configuration and keep your HTTP credentials:

```toml title="logbrook.toml"
[indexes.application]

[forward]
enabled = true

[[forward.listeners]]
name = "docker-local"
bind = "127.0.0.1:24224"
security = "trusted_local"
principal = "docker-host"

[forward.principals.docker-host]
source = "docker-host"
indexes = ["application"]

[[forward.routes]]
listener = "docker-local"
tag_prefix = "application."
index = "application"
normalizer = "docker"
json_profile = "json_auto"
service_from = "tag_suffix"
host = "application-host"
```

This creates:

- A listener on loopback that trusts every local client. See [authentication](https://sandrinodm.github.io/logbrook/configure/forward-listener/#authentication).
- A principal that fixes the stored `source` to `docker-host` and limits writes to the `application` index.
- A route that sends every tag starting with `application.` to the `application` index, parses Docker records, and takes the service name from the rest of the tag.

Nothing in a record can change its source or index. Use `tag` instead of `tag_prefix` to match one exact tag. Routes on the same listener can't overlap.

## Run a local Docker route

The server runs on the same host as the Docker daemon, with the configuration above.

1. **Validate the configuration**

   ```sh
   logbrook --config logbrook.toml check-config
   ```

   ```text
   Configuration is valid
   ```
2. **Start the server**

   Restart `logbrook serve` so it loads the `[forward]` section. If a listener can't bind, startup fails and the HTTP API doesn't start.
3. **Start a container with the fluentd driver**

   ```sh
   docker run --rm \
     --log-driver fluentd \
     --log-opt fluentd-address=127.0.0.1:24224 \
     --log-opt fluentd-async=true \
     --log-opt fluentd-request-ack=true \
     --log-opt fluentd-sub-second-precision=true \
     --log-opt tag=application.api \
     busybox:1.37 sh -c 'echo logbrook-forward-test; sleep 2'
   ```
4. **Query the event**

   ```sh
   export LOGBROOK_URL=http://127.0.0.1:3100
   export LOGBROOK_READ_TOKEN='<your read token>'

   logbrook query application --since 5m --service api --json
   ```

   The event has `service` `api` (from the tag suffix), `host` `application-host`, `source` `docker-host`, and the container line as `message`.

> **Check your Docker version**
>
> Containers pick up logging options only when they are created. Check the options against your Docker Engine version and send a test event before you move real traffic.

## Configure containers

Set the driver and its options per container, with `--log-driver` and `--log-opt` as in the walkthrough, or in Compose:

```yaml title="compose.yaml"
services:
  api:
    image: your-image
    logging:
      driver: fluentd
      options:
        fluentd-address: "127.0.0.1:24224"
        fluentd-async: "true"
        fluentd-sub-second-precision: "true"
        fluentd-request-ack: "true"
        fluentd-buffer-limit: "8192"
        fluentd-write-timeout: "5s"
        tag: "application.api"
        cache-max-size: "10m"
        cache-max-file: "3"
```

The Docker daemon connects, not the container, so `127.0.0.1` means the host.

| Option | Why |
| --- | --- |
| `fluentd-address` | Where the daemon connects. |
| `tag` | Must match a route. Here `application.api` matches `application.` and gives the service `api`. |
| `fluentd-request-ack` | Ask Logbrook to confirm each envelope after it commits. |
| `fluentd-async` | Keep on whenever you set `fluentd-request-ack`. |
| `fluentd-sub-second-precision` | Send timestamps with sub-second precision. |
| `fluentd-write-timeout` | Limits socket writes. It doesn't limit the wait for an ACK. |
| `cache-max-size`, `cache-max-file` | Keep a local copy for `docker logs` only. |

> **Keep fluentd-async on with ACKs**
>
> Without `fluentd-async`, Docker Engine 28.0.4 (whose driver uses fluent-logger-golang 1.9.0) sends stdout and stderr lines from separate goroutines over one connection and can mix up their ACKs. The driver then resends both lines in a loop without backoff, which stores duplicates and overloads the receiver. In async mode the driver sends one envelope at a time.

## Run Logbrook in a container

To receive Forward traffic inside a container, bind `0.0.0.0:24224`, set `trusted_network = true`, and publish the port on loopback only, for example `127.0.0.1:24524:24224`. Containers then log to `127.0.0.1:24524`.

> **Any container on the network can connect**
>
> A `trusted_local` listener has no authentication. Any other container on the receiver's network can write once `trusted_network = true`. Use an isolated network, or an authenticated listener for sources you don't trust.

The [Forward Compose example](https://github.com/sandrinodm/logbrook/tree/main/examples/forward) does this. It keeps the image's non-root user, a read-only root filesystem, all capabilities dropped and a 35-second stop grace period. Its configuration:

```toml title="examples/forward/logbrook.toml"
# HTTP credentials are provided by compose.yaml environment variables.
bind = "0.0.0.0:3100"

[indexes.application]

[forward]
enabled = true

[[forward.listeners]]
name = "docker"
bind = "0.0.0.0:24224"
security = "trusted_local"
trusted_network = true
principal = "docker-host"

[forward.principals.docker-host]
source = "docker-host"
indexes = ["application"]

[[forward.routes]]
listener = "docker"
tag_prefix = "application."
index = "application"
normalizer = "docker"
json_profile = "json_auto"
service_from = "tag_suffix"
host = "docker-host"
```

The server service in its `compose.yaml` publishes both ports on loopback:

```yaml title="examples/forward/compose.yaml"
    ports:
      - "127.0.0.1:3100:3100"
      - "127.0.0.1:24524:24224"
```

A `smoke` profile starts a disposable BusyBox container that logs one synthetic line through the driver:

```sh
cd examples/forward
export LOGBROOK_INGEST_TOKEN='<random ingestion token>'
export LOGBROOK_READ_TOKEN='<different random read token>'

docker compose up -d logbrook
docker compose --profile smoke run --rm producer
```

Then query `application` for the `logbrook-forward-synthetic` message.

## Use Fluentd or Fluent Bit

Create a listener, a principal and a route as above, with a route `tag` or `tag_prefix` that matches the tags your collector emits, then point the collector's forward output at the listener.

```text title="Fluent Bit"
[OUTPUT]
    Name                  forward
    Match                 application.*
    Host                  logbrook.internal
    Port                  24224
    Require_ack_response  On
```

```text title="Fluentd"
<match application.**>
  @type forward
  require_ack_response true
  heartbeat_type none
  <server>
    host logbrook.internal
    port 24224
  </server>
</match>
```

These snippets use the same output options as the repository's collector interoperability harness (`tests/tools/forward_interop.py`), which also turns on gzip compression. Check them against your collector version.

- Use a `generic` route (the default `normalizer`) for collector output. A generic route doesn't detect Docker records from a `log` field.
- Fluentd 1.20.1 defaults to `heartbeat_type transport`. For ACK-based TCP or TLS delivery, `heartbeat_type none` skips the separate probes and relies on the ACK timeout. If the sender uses UDP heartbeats, set `udp_heartbeat = true` on the listener. A non-loopback listener then also needs `allow_peers`.
- Across a network you don't trust, use a `shared_key` listener with TLS, or `mtls`. See [authentication](https://sandrinodm.github.io/logbrook/configure/forward-listener/#authentication).

## Delivery and acknowledgements

Logbrook validates each envelope as a whole and commits it to one index in one transaction. It never splits an envelope.

- If the envelope carries a `chunk` option, Logbrook sends the ACK only after the commit. An ACK means the whole envelope is stored.
- An empty envelope is a valid no-op and is ACKed.
- A corrupt last entry or a bad gzip checksum rejects every entry in the envelope.
- Rejected, overloaded or failed envelopes close the connection without an ACK. There is no negative ACK with a reason, so a sender can retry a permanently invalid record forever. Check `logbrook_forward_*` [metrics](https://sandrinodm.github.io/logbrook/configure/forward-listener/#metrics) and the server log for the reason.
- A commit that has started finishes even if the client disconnects.

> **Retries can store duplicates**
>
> A missing ACK doesn't mean the envelope failed. A sender that retries after losing the connection or the ACK can store duplicates. Logbrook has no deduplication, and Forward is not exactly-once.

On shutdown Logbrook stops accepting envelopes, drops incomplete frames without an ACK, and finishes admitted commits and their ACKs within `shutdown_timeout_secs`. The sender may retry anything not ACKed by then.

Supported modes are Message, Forward, PackedForward (as `bin` or `str`) and gzip CompressedPackedForward, including payloads made of several gzip members. Timestamps can be integer seconds or EventTime. Not supported: JSON transport, zstd, metrics and traces, reassembly of fragmented records, quarantine of rejected records, deduplication, replication and clustering.

## How records become events

Events are stored with millisecond precision. The original seconds and nanoseconds are kept in `attributes.forward`.

### Generic routes

A generic route stores the record under `attributes.application`. The message is the first string field listed in `message_fields` (default `["message", "msg"]`), or the record as JSON when none matches.

### Docker routes

A route with `normalizer = "docker"` needs `container_id`, `container_name`, `source` and `log`, each present once as a string. Otherwise the event is stored as a generic record with a fallback marker in `attributes.logbrook`.

- The driver's `source` (stdout or stderr) goes to `attributes.docker.stream`, not the stored source.
- `container_name` keeps its leading slash.
- Other driver fields go to `attributes.docker.extra`.

The `json_profile` setting decides how the `log` line is read:

| `json_profile` | Message and level |
| --- | --- |
| `text` (default) | The line as is, at `default_level` (default 30). |
| `pino` | String `msg` and a nonnegative integer `level`. |
| `json_auto` | The first string in `message_fields`. The level comes from `level` or `severity` by name. |

`json_auto` maps level names, ignoring case: trace 10, debug 20, info 30, warn or warning 40, error 50, fatal or critical 60. Anything else gets `default_level`. Both JSON profiles also read `logger` or `name`, a nonnegative integer `pid`, and `service`.

A line that isn't a JSON object with a message keeps the original line, including whitespace and stack traces. With a JSON profile, a line that parses as a JSON object has its fields stored as one object under `attributes.application` (under `attributes.docker.parsed_application` for a typed record), and `attributes.logbrook.parse_status` says how the line was read: `structured`, `json_without_message`, `json_depth_limit`, `text` or `fragment`. When parsing changes the message, the route's `original_line` option decides whether the original line is also stored in `attributes.docker.log`.

### Original line

A parsed JSON line holds the same information twice: once as the message and the application's fields, and once as the raw line. The `original_line` route option decides when the raw line is kept:

```toml
original_line = "on_parse_failure"   # default; or "always"
```

| `original_line` | `attributes.docker.log` |
| --- | --- |
| `on_parse_failure` (default) | Left out of an event whose line was parsed without loss. Kept otherwise. |
| `always` | Kept whenever parsing changed the message. |

With `on_parse_failure`, an event whose line was parsed as a JSON object with a message and without loss has no `attributes.docker.log`. It gets `attributes.logbrook.original_line = "omitted"` instead, so you can tell an omitted line from one that was never stored.

Logbrook keeps the line, with no marker, when parsing would change what the line says:

- An integer is outside the range of a signed or unsigned 64-bit integer.
- A number with a fraction or exponent would not print back with the same digits after being stored as a 64-bit float. A number like `0.1` or `1e3` doesn't count, because it's stored as the same number.
- An object repeats a key. Parsing keeps only the last value.
- The record is a typed record, which Logbrook preserves with `msgpack_typed_v1`. See [Binary and unusual records](#binary-and-unusual-records).

Lines that were not parsed as a JSON object with a message, such as text lines, fragments, lines over the depth limit and JSON without a message, never had a second copy: the message already is the line, so `attributes.docker.log` is not stored for them in either mode.

The stored fields are equivalent to the line but not byte for byte. Whitespace, key order and string escapes are not kept. If you need the exact bytes of every line, set `original_line = "always"`, which restores the behavior of releases before 0.5.0. The option applies to events received after the change. Events stored earlier are not rewritten. Generic routes are not affected.

### Application attributes

By default the application's fields stay together under `attributes.application`. [Attribute filters](https://sandrinodm.github.io/logbrook/query/attribute-filters/) match only top-level attributes, so a field such as `runId` can't be filtered there. To store the fields at the top level of `attributes` instead, set `application_attributes` on the route (available since 0.4.0):

```toml
application_attributes = "top_level"   # default: "nested"
```

With `top_level`, a field like `runId` is stored at `attributes.runId`, and `attributes.application` is removed. The message, level, logger, pid, service and application time are derived as before. On a Docker route, the fields are the top-level keys of the JSON log line, so the line must parse as a JSON object (`parse_status` is `structured` or `json_without_message`).

Logbrook writes `forward`, `docker` and `logbrook` at the top level itself. An application field with one of those names is stored in `attributes.logbrook.conflicting_fields` instead. A field named `application` is an ordinary field and is stored at `attributes.application`.

Each event that is moved gets `attributes.forward.application_attributes = "top_level"`. These events are left as the default layout produces them, with no marker:

- Typed records preserved with `msgpack_typed_v1`.
- Docker events whose log line isn't parsed as a JSON object: text lines, fragments and lines over the depth limit.
- Records on Docker routes that aren't Docker records. They're stored as generic records with `attributes.logbrook.docker_status = "generic_fallback"`.

Only the top-level keys of the record or JSON line move. Nested objects stay as they are. The option applies to events received after the change. Events stored earlier are not rewritten. The new keys count toward the same size limits as any other attribute.

Fields that move become ordinary attributes. Fields such as `msg`, `level`, `time` and `service` are separate from the event's own message, level, timestamp and service. A filter on the attribute `level` matches that field's value only. It is not a severity filter; use `min_level` for that.

On a Docker route with `json_profile = "text"` (the default), the log line isn't parsed, so no fields move. Generic routes move the record's fields whatever `json_profile` says. `original_line` works the same with either value.

Numbers keep the value they have after projection. A MessagePack `float32` is stored widened to `float64`, so `0.1` sent as `float32` is stored as `0.10000000149011612`, and an equality filter on `0.1` doesn't match it.

### Service, host and time

The stored service is the first of these that is set:

1. The route's `service`, or the tag suffix when `service_from = "tag_suffix"`.
2. The field named by `compose_service_label`, at the top level or inside a `labels` map.
3. The application's `service` field.
4. The container name without its leading slash.

The host comes only from the route's `host`, never from the peer address.

Events use the Forward timestamp by default. To use a timestamp from the record, set both `application_time_field = "time"` and `application_time_format = "unix_ms"` (or `"unix_seconds"`). The value must be an integer within the index's retention window and future-skew limit. Otherwise the event keeps the Forward timestamp, and `attributes.logbrook.application_time_status` records why.

### Long lines

Docker splits long lines into partial messages. A record with any `partial_*` field is stored as its own event without JSON parsing, with `partial_id`, `partial_ordinal`, `partial_last`, the original fields and a validity flag in `attributes.docker.fragment`. Logbrook never reassembles them.

### Binary and unusual records

Records must be maps with string keys at the top level, or the envelope is rejected. Records with unique UTF-8 keys and JSON-compatible values are stored as plain JSON. Records with duplicate keys, invalid UTF-8, binary values, unknown extensions, non-finite floats or non-string nested keys use the `msgpack_typed_v1` encoding. The exact original bytes are kept in `attributes.forward.original_record_msgpack_b64`.

Fluent Bit's logs metadata format is supported when the envelope sets `fluent_signal = 0`. The metadata goes to `attributes.forward.metadata`. Other signal values and malformed metadata are rejected.

## Next steps

- [Forward listener reference](https://sandrinodm.github.io/logbrook/configure/forward-listener/) — Every listener, route, limit and metric.
- [Attribute filters](https://sandrinodm.github.io/logbrook/query/attribute-filters/) — Filter on fields stored under attributes.
- [Run in production](https://sandrinodm.github.io/logbrook/operate/production/) — Harden and monitor the deployment.

Source: https://sandrinodm.github.io/logbrook/send-logs/docker-forward/index.mdx
