The fluentd logging driver sends container logs to the
Fluentd collector as structured log data. Then, users
can use any of the various output plugins of
Fluentd to write these logs to various
destinations.
In addition to the log message itself, the fluentd log
driver sends the following metadata in the structured log message:
Field
Description
container_id
The full 64-character container ID.
container_name
The container name at the time it was started. If you use docker rename to rename a container, the new name isn't reflected in the journal entries.
Some options are supported by specifying --log-opt as many times as needed:
fluentd-address: specify a socket address to connect to the Fluentd daemon, ex fluentdhost:24224 or unix:///path/to/fluentd.sock.
tag: specify a tag for Fluentd messages. Supports some Go template markup, ex {{.ID}}, {{.FullID}} or {{.Name}}docker.{{.ID}}.
To use the fluentd driver as the default logging driver, set the log-driver
and log-opt keys to appropriate values in the daemon.json file. For more
about configuring Docker using daemon.json, see
daemon.json.
{{% include "daemon-cfg-desktop.md" %}}
The following example sets the log driver to fluentd and sets the
fluentd-address option.
log-opts configuration options in the daemon.json configuration file must
be provided as strings. Boolean and numeric values (such as the value for
fluentd-async or fluentd-max-retries) must therefore be enclosed
in quotes (").
To set the logging driver for a specific container, pass the
--log-driver option to docker run:
$ dockerrun--log-driver=fluentd...
Before using this logging driver, launch a Fluentd daemon. The logging driver
connects to this daemon through localhost:24224 by default. Use the
fluentd-address option to connect to a different address.
By default, the logging driver connects to localhost:24224. Supply the
fluentd-address option to connect to a different address. tcp(default) and unix sockets are supported.
By default, Docker uses the first 12 characters of the container ID to tag log messages.
Refer to the log tag option documentation for customizing
the log tag format.
The labels and env options each take a comma-separated list of keys. If
there is collision between label and env keys, the value of the env takes
precedence. Both options add additional fields to the extra attributes of a
logging message.
The env-regex and labels-regex options are similar to and compatible with
respectively env and labels. Their values are regular expressions to match
logging-related environment variables and labels. It is used for advanced
log tag options.
When fluentd-async is enabled, the fluentd-async-reconnect-interval option
defines the interval, in milliseconds, at which the connection to
fluentd-address is re-established. This option is useful if the address
resolves to one or more IP addresses, for example a Consul service address.
Sets the number of events buffered on the memory. Records will be stored in memory
up to this number. If the buffer is full, the call to record logs will fail.
The default is 1048576.
(https://github.com/fluent/fluent-logger-golang/tree/master#bufferlimit)
To use this logging driver, start the fluentd daemon on a host. We recommend
that you use the Fluentd docker
image. This image is
especially useful if you want to aggregate multiple container logs on each
host then, later, transfer the logs to another Fluentd node to create an
aggregate store.