github.com/sijibomii/docker@v0.0.0-20231230191044-5cf6ca554647/docs/admin/logging/fluentd.md (about)

     1  <!--[metadata]>
     2  +++
     3  aliases = ["/engine/reference/logging/fluentd/"]
     4  title = "Fluentd logging driver"
     5  description = "Describes how to use the fluentd logging driver."
     6  keywords = ["Fluentd, docker, logging, driver"]
     7  [menu.main]
     8  parent = "smn_logging"
     9  weight=2
    10  +++
    11  <![end-metadata]-->
    12  
    13  # Fluentd logging driver
    14  
    15  The `fluentd` logging driver sends container logs to the
    16  [Fluentd](http://www.fluentd.org/) collector as structured log data. Then, users
    17  can use any of the [various output plugins of
    18  Fluentd](http://www.fluentd.org/plugins) to write these logs to various
    19  destinations.
    20  
    21  In addition to the log message itself, the `fluentd` log
    22  driver sends the following metadata in the structured log message:
    23  
    24  | Field            | Description                         |
    25  -------------------|-------------------------------------|
    26  | `container_id`   | The full 64-character container ID. |
    27  | `container_name` | The container name at the time it was started. If you use `docker rename` to rename a container, the new name is not reflected in the journal entries.                                         |
    28  | `source`         | `stdout` or `stderr`                |
    29  
    30  The `docker logs` command is not available for this logging driver.
    31  
    32  ## Usage
    33  
    34  Some options are supported by specifying `--log-opt` as many times as needed:
    35  
    36   - `fluentd-address`: specify `host:port` to connect `localhost:24224`
    37   - `tag`: specify tag for fluentd message, which interpret some markup, ex `{{.ID}}`, `{{.FullID}}` or `{{.Name}}` `docker.{{.ID}}`
    38  
    39  
    40  Configure the default logging driver by passing the
    41  `--log-driver` option to the Docker daemon:
    42  
    43      docker daemon --log-driver=fluentd
    44  
    45  To set the logging driver for a specific container, pass the
    46  `--log-driver` option to `docker run`:
    47  
    48      docker run --log-driver=fluentd ...
    49  
    50  Before using this logging driver, launch a Fluentd daemon. The logging driver
    51  connects to this daemon through `localhost:24224` by default. Use the
    52  `fluentd-address` option to connect to a different address.
    53  
    54      docker run --log-driver=fluentd --log-opt fluentd-address=myhost.local:24224
    55  
    56  If container cannot connect to the Fluentd daemon, the container stops
    57  immediately unless the `fluentd-async-connect` option is used.
    58  
    59  ## Options
    60  
    61  Users can use the `--log-opt NAME=VALUE` flag to specify additional Fluentd logging driver options.
    62  
    63  ### fluentd-address
    64  
    65  By default, the logging driver connects to `localhost:24224`. Supply the
    66  `fluentd-address` option to connect to a different address.
    67  
    68      docker run --log-driver=fluentd --log-opt fluentd-address=myhost.local:24224
    69  
    70  ### tag
    71  
    72  By default, Docker uses the first 12 characters of the container ID to tag log messages.
    73  Refer to the [log tag option documentation](log_tags.md) for customizing
    74  the log tag format.
    75  
    76  
    77  ### labels and env
    78  
    79  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.
    80  
    81  ### fluentd-async-connect
    82  
    83  Docker connects to Fluentd in the background. Messages are buffered until the connection is established.
    84  
    85  ## Fluentd daemon management with Docker
    86  
    87  About `Fluentd` itself, see [the project webpage](http://www.fluentd.org)
    88  and [its documents](http://docs.fluentd.org/).
    89  
    90  To use this logging driver, start the `fluentd` daemon on a host. We recommend
    91  that you use [the Fluentd docker
    92  image](https://hub.docker.com/r/fluent/fluentd/). This image is
    93  especially useful if you want to aggregate multiple container logs on a each
    94  host then, later, transfer the logs to another Fluentd node to create an
    95  aggregate store.
    96  
    97  ### Testing container loggers
    98  
    99  1. Write a configuration file (`test.conf`) to dump input logs:
   100  
   101          <source>
   102            @type forward
   103          </source>
   104  
   105          <match docker.**>
   106            @type stdout
   107          </match>
   108  
   109  2. Launch Fluentd container with this configuration file:
   110  
   111          $ docker run -it -p 24224:24224 -v /path/to/conf/test.conf:/fluentd/etc -e FLUENTD_CONF=test.conf fluent/fluentd:latest
   112  
   113  3. Start one or more containers with the `fluentd` logging driver:
   114  
   115          $ docker run --log-driver=fluentd your/application