chore: tier 1 freshness: content/config/containers/logging/fluentd.md

Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
This commit is contained in:
David Karlsson 2023-10-27 07:05:55 +02:00
parent 33d73761d7
commit d82daa0186
1 changed files with 46 additions and 39 deletions

View File

@ -1,11 +1,11 @@
--- ---
description: Describes how to use the fluentd logging driver. description: Learn how to use the fluentd logging driver
keywords: Fluentd, docker, logging, driver keywords: Fluentd, docker, logging, driver
title: Fluentd logging driver title: Fluentd logging driver
aliases: aliases:
- /engine/reference/logging/fluentd/ - /engine/reference/logging/fluentd/
- /reference/logging/fluentd/ - /reference/logging/fluentd/
- /engine/admin/logging/fluentd/ - /engine/admin/logging/fluentd/
--- ---
The `fluentd` logging driver sends container logs to the The `fluentd` logging driver sends container logs to the
@ -18,40 +18,38 @@ In addition to the log message itself, the `fluentd` log
driver sends the following metadata in the structured log message: driver sends the following metadata in the structured log message:
| Field | Description | | Field | Description |
|:-----------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------| | :--------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------- |
| `container_id` | The full 64-character container ID. | | `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 is not reflected in the journal entries. | | `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. |
| `source` | `stdout` or `stderr` | | `source` | `stdout` or `stderr` |
| `log` | The container log | | `log` | The container log |
The `docker logs` command is not available for this logging driver. The `docker logs` command isn't available for this logging driver.
## Usage ## Usage
Some options are supported by specifying `--log-opt` as many times as needed: 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` - `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 message, which interprets some markup, ex `{{.ID}}`, `{{.FullID}}` or `{{.Name}}` `docker.{{.ID}}` - `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`
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, which is
and `log-opt` keys to appropriate values in the `daemon.json` file, which is located in `/etc/docker/` on Linux hosts or
located in `/etc/docker/` on Linux hosts or `C:\ProgramData\docker\config\daemon.json` on Windows Server. For more about
`C:\ProgramData\docker\config\daemon.json` on Windows Server. For more about configuring Docker using `daemon.json`, see [daemon.json](../../../engine/reference/commandline/dockerd.md#daemon-configuration-file).
+configuring Docker using `daemon.json`, see
+[daemon.json](../../../engine/reference/commandline/dockerd.md#daemon-configuration-file).
The following example sets the log driver to `fluentd` and sets the The following example sets the log driver to `fluentd` and sets the
`fluentd-address` option. `fluentd-address` option.
```json ```json
{ {
"log-driver": "fluentd", "log-driver": "fluentd",
"log-opts": { "log-opts": {
"fluentd-address": "fluentdhost:24224" "fluentd-address": "fluentdhost:24224"
} }
} }
``` ```
Restart Docker for the changes to take effect. Restart Docker for the changes to take effect.
@ -65,13 +63,17 @@ Restart Docker for the changes to take effect.
To set the logging driver for a specific container, pass the To set the logging driver for a specific container, pass the
`--log-driver` option to `docker run`: `--log-driver` option to `docker run`:
docker run --log-driver=fluentd ... ```text
docker run --log-driver=fluentd ...
```
Before using this logging driver, launch a Fluentd daemon. The logging driver Before using this logging driver, launch a Fluentd daemon. The logging driver
connects to this daemon through `localhost:24224` by default. Use the connects to this daemon through `localhost:24224` by default. Use the
`fluentd-address` option to connect to a different address. `fluentd-address` option to connect to a different address.
docker run --log-driver=fluentd --log-opt fluentd-address=fluentdhost:24224 ```text
docker run --log-driver=fluentd --log-opt fluentd-address=fluentdhost:24224
```
If container cannot connect to the Fluentd daemon, the container stops If container cannot connect to the Fluentd daemon, the container stops
immediately unless the `fluentd-async` option is used. immediately unless the `fluentd-async` option is used.
@ -97,7 +99,6 @@ By default, Docker uses the first 12 characters of the container ID to tag log m
Refer to the [log tag option documentation](log_tags.md) for customizing Refer to the [log tag option documentation](log_tags.md) for customizing
the log tag format. the log tag format.
### labels, labels-regex, env, and env-regex ### labels, labels-regex, env, and env-regex
The `labels` and `env` options each take a comma-separated list of keys. If The `labels` and `env` options each take a comma-separated list of keys. If
@ -128,7 +129,7 @@ How long to wait between retries. Defaults to 1 second.
### fluentd-max-retries ### fluentd-max-retries
The maximum number of retries. Defaults to `4294967295` (2**32 - 1). The maximum number of retries. Defaults to `4294967295` (2\*\*32 - 1).
### fluentd-sub-second-precision ### fluentd-sub-second-precision
@ -150,6 +151,7 @@ aggregate store.
1. Write a configuration file (`test.conf`) to dump input logs: 1. Write a configuration file (`test.conf`) to dump input logs:
```none
<source> <source>
@type forward @type forward
</source> </source>
@ -157,11 +159,16 @@ aggregate store.
<match *> <match *>
@type stdout @type stdout
</match> </match>
```none
2. Launch Fluentd container with this configuration file: 2. Launch Fluentd container with this configuration file:
```none
$ docker run -it -p 24224:24224 -v /path/to/conf/test.conf:/fluentd/etc/test.conf -e FLUENTD_CONF=test.conf fluent/fluentd:latest $ docker run -it -p 24224:24224 -v /path/to/conf/test.conf:/fluentd/etc/test.conf -e FLUENTD_CONF=test.conf fluent/fluentd:latest
```
3. Start one or more containers with the `fluentd` logging driver: 3. Start one or more containers with the `fluentd` logging driver:
```none
$ docker run --log-driver=fluentd your/application $ docker run --log-driver=fluentd your/application
```