github.com/hustcat/docker@v1.3.3-0.20160314103604-901c67a8eeab/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 - `fail-on-startup-error`: true/false; Should the logging driver fail container startup in case of connect error during startup. Default: true (backwards compatible) 39 - `buffer-limit`: Size limit (bytes) for the buffer which is used to buffer messages in case of connection outages. Default: 1M 40 41 Configure the default logging driver by passing the 42 `--log-driver` option to the Docker daemon: 43 44 docker daemon --log-driver=fluentd 45 46 To set the logging driver for a specific container, pass the 47 `--log-driver` option to `docker run`: 48 49 docker run --log-driver=fluentd ... 50 51 Before using this logging driver, launch a Fluentd daemon. The logging driver 52 connects to this daemon through `localhost:24224` by default. Use the 53 `fluentd-address` option to connect to a different address. 54 55 docker run --log-driver=fluentd --log-opt fluentd-address=myhost.local:24224 56 57 If container cannot connect to the Fluentd daemon, the container stops 58 immediately. 59 60 ## Options 61 62 Users can use the `--log-opt NAME=VALUE` flag to specify additional Fluentd logging driver options. 63 64 ### fluentd-address 65 66 By default, the logging driver connects to `localhost:24224`. Supply the 67 `fluentd-address` option to connect to a different address. 68 69 docker run --log-driver=fluentd --log-opt fluentd-address=myhost.local:24224 70 71 ### tag 72 73 By default, Docker uses the first 12 characters of the container ID to tag log messages. 74 Refer to the [log tag option documentation](log_tags.md) for customizing 75 the log tag format. 76 77 78 ### labels and env 79 80 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. 81 82 ### fail-on-startup-error 83 84 By default, if the logging driver cannot connect to the backend it will fail the entire startup of the container. If you wish to ignore potential connect error during container startup supply the `fail-on-startup-error` flag. 85 86 docker run --log-driver=fluentd --log-opt fail-on-startup-error=false 87 88 89 ### buffer-limit 90 91 When fluent driver loses connection, or cannot connect at container startup, it will buffer the log events locally for re-transmission. Buffer limit option controls how much data will be buffered locally, **per container**. Specified in bytes. 92 93 docker run --log-driver=fluentd --log-opt buffer-limit=5242880 94 95 The above would result to use 5M buffer locally. Keep in mind that during possible connection errors all your containers will start buffering locally and thus might result in considerable memory usage. 96 97 ## Fluentd daemon management with Docker 98 99 About `Fluentd` itself, see [the project webpage](http://www.fluentd.org) 100 and [its documents](http://docs.fluentd.org/). 101 102 To use this logging driver, start the `fluentd` daemon on a host. We recommend 103 that you use [the Fluentd docker 104 image](https://hub.docker.com/r/fluent/fluentd/). This image is 105 especially useful if you want to aggregate multiple container logs on a each 106 host then, later, transfer the logs to another Fluentd node to create an 107 aggregate store. 108 109 ### Testing container loggers 110 111 1. Write a configuration file (`test.conf`) to dump input logs: 112 113 <source> 114 @type forward 115 </source> 116 117 <match docker.**> 118 @type stdout 119 </match> 120 121 2. Launch Fluentd container with this configuration file: 122 123 $ docker run -it -p 24224:24224 -v /path/to/conf/test.conf:/fluentd/etc -e FLUENTD_CONF=test.conf fluent/fluentd:latest 124 125 3. Start one or more containers with the `fluentd` logging driver: 126 127 $ docker run --log-driver=fluentd your/application