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

Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
This commit is contained in:
David Karlsson 2023-10-27 13:40:24 +02:00
parent 11d7363943
commit 36e36d030f
1 changed files with 40 additions and 43 deletions

View File

@ -1,41 +1,42 @@
--- ---
description: Configure logging driver. description: Learn how to configure logging driver for the Docker daemon
keywords: docker, logging, driver keywords: docker, logging, driver
title: Configure logging drivers title: Configure logging drivers
aliases: aliases:
- /engine/reference/logging/overview/ - /engine/reference/logging/overview/
- /engine/reference/logging/ - /engine/reference/logging/
- /engine/admin/reference/logging/ - /engine/admin/reference/logging/
- /engine/admin/logging/overview/ - /engine/admin/logging/overview/
--- ---
Docker includes multiple logging mechanisms to help you Docker includes multiple logging mechanisms to help you
[get information from running containers and services](index.md). [get information from running containers and services](index.md).
These mechanisms are called logging drivers. Each Docker daemon has a default These mechanisms are called logging drivers. Each Docker daemon has a default
logging driver, which each container uses unless you configure it to use a logging driver, which each container uses unless you configure it to use a
different logging driver, or "log-driver" for short. different logging driver, or log driver for short.
As a default, Docker uses the [`json-file` logging driver](json-file.md), which As a default, Docker uses the [`json-file` logging driver](json-file.md), which
caches container logs as JSON internally. In addition to using the logging drivers caches container logs as JSON internally. In addition to using the logging drivers
included with Docker, you can also implement and use [logging driver plugins](plugins.md). included with Docker, you can also implement and use [logging driver plugins](plugins.md).
> **Tip: use the "local" logging driver to prevent disk-exhaustion** > **Tip: use the `local` logging driver to prevent disk-exhaustion**
> >
> By default, no log-rotation is performed. As a result, log-files stored by the > By default, no log-rotation is performed. As a result, log-files stored by the
> default [`json-file` logging driver](json-file.md) logging driver can cause > default [`json-file` logging driver](json-file.md) logging driver can cause
> a significant amount of disk space to be used for containers that generate much > a significant amount of disk space to be used for containers that generate much
> output, which can lead to disk space exhaustion. > output, which can lead to disk space exhaustion.
> >
> Docker keeps the json-file logging driver (without log-rotation) as a default > Docker keeps the json-file logging driver (without log-rotation) as a default
> to remain backward compatibility with older versions of Docker, and for situations > to remain backward compatibility with older versions of Docker, and for situations
> where Docker is used as runtime for Kubernetes. > where Docker is used as runtime for Kubernetes.
> >
> For other situations, the "local" logging driver is recommended as it performs > For other situations, the `local` logging driver is recommended as it performs
> log-rotation by default, and uses a more efficient file format. Refer to the > log-rotation by default, and uses a more efficient file format. Refer to the
> [Configure the default logging driver](#configure-the-default-logging-driver) > [Configure the default logging driver](#configure-the-default-logging-driver)
> section below to learn how to configure the "local" logging driver as a default, > section below to learn how to configure the `local` logging driver as a default,
> and the [local file logging driver](local.md) page for more details about the > and the [local file logging driver](local.md) page for more details about the
> "local" logging driver. > `local` logging driver.
{ .tip }
## Configure the default logging driver ## Configure the default logging driver
@ -71,7 +72,7 @@ example sets four configurable options on the `json-file` logging driver:
``` ```
Restart Docker for the changes to take effect for newly created containers. Restart Docker for the changes to take effect for newly created containers.
Existing containers do not use the new logging configuration. Existing containers don't use the new logging configuration automatically.
> **Note** > **Note**
> >
@ -79,21 +80,19 @@ Existing containers do not use the new logging configuration.
> be provided as strings. Boolean and numeric values (such as the value for > be provided as strings. Boolean and numeric values (such as the value for
> `max-file` in the example above) must therefore be enclosed in quotes (`"`). > `max-file` in the example above) must therefore be enclosed in quotes (`"`).
If you do not specify a logging driver, the default is `json-file`. If you don't specify a logging driver, the default is `json-file`.
To find the current default logging driver for the Docker daemon, run To find the current default logging driver for the Docker daemon, run
`docker info` and search for `Logging Driver`. You can use the following `docker info` and search for `Logging Driver`. You can use the following
command on Linux, macOS, or PowerShell on Windows: command on Linux, macOS, or PowerShell on Windows:
```console ```console
$ docker info --format '{{.LoggingDriver}}' $ docker info --format '{{.LoggingDriver}}'
json-file json-file
``` ```
> **Note** > **Note**
> >
> Changing the default logging driver or logging driver options in the daemon > Changing the default logging driver or logging driver options in the daemon
> configuration only affects containers that are created after the configuration > configuration only affects containers that are created after the configuration
> is changed. Existing containers retain the logging driver options that were > is changed. Existing containers retain the logging driver options that were
@ -121,21 +120,19 @@ To find the current logging driver for a running container, if the daemon
is using the `json-file` logging driver, run the following `docker inspect` is using the `json-file` logging driver, run the following `docker inspect`
command, substituting the container name or ID for `<CONTAINER>`: command, substituting the container name or ID for `<CONTAINER>`:
```console ```console
$ docker inspect -f '{{.HostConfig.LogConfig.Type}}' <CONTAINER> $ docker inspect -f '{{.HostConfig.LogConfig.Type}}' <CONTAINER>
json-file json-file
``` ```
## Configure the delivery mode of log messages from container to log driver ## Configure the delivery mode of log messages from container to log driver
Docker provides two modes for delivering messages from the container to the log Docker provides two modes for delivering messages from the container to the log
driver: driver:
* (default) direct, blocking delivery from container to driver - (default) direct, blocking delivery from container to driver
* non-blocking delivery that stores log messages in an intermediate per-container buffer for consumption by driver - non-blocking delivery that stores log messages in an intermediate per-container buffer for consumption by driver
The `non-blocking` message delivery mode prevents applications from blocking due The `non-blocking` message delivery mode prevents applications from blocking due
to logging back pressure. Applications are likely to fail in unexpected ways when to logging back pressure. Applications are likely to fail in unexpected ways when
@ -143,7 +140,7 @@ STDERR or STDOUT streams block.
> **Warning** > **Warning**
> >
> When the buffer is full, new messages will not be enqueued. Dropping messages is often preferred to blocking the > When the buffer is full, new messages will not be enqueued. Dropping messages is often preferred to blocking the
> log-writing process of an application. > log-writing process of an application.
{ .warning } { .warning }
@ -165,8 +162,8 @@ $ docker run -it --log-opt mode=non-blocking --log-opt max-buffer-size=4m alpine
Some logging drivers add the value of a container's `--env|-e` or `--label` Some logging drivers add the value of a container's `--env|-e` or `--label`
flags to the container's logs. This example starts a container using the Docker flags to the container's logs. This example starts a container using the Docker
daemon's default logging driver (let's assume `json-file`) but sets the daemon's default logging driver (in the following example, `json-file`) but
environment variable `os=ubuntu`. sets the environment variable `os=ubuntu`.
```console ```console
$ docker run -dit --label production_status=testing -e os=ubuntu alpine sh $ docker run -dit --label production_status=testing -e os=ubuntu alpine sh
@ -186,33 +183,33 @@ documentation for its configurable options, if applicable. If you are using
[logging driver plugins](plugins.md), you may [logging driver plugins](plugins.md), you may
see more options. see more options.
| Driver | Description | | Driver | Description |
|:------------------------------|:--------------------------------------------------------------------------------------------------------------| | :---------------------------- | :---------------------------------------------------------------------------------------------------------- |
| `none` | No logs are available for the container and `docker logs` does not return any output. | | `none` | No logs are available for the container and `docker logs` does not return any output. |
| [`local`](local.md) | Logs are stored in a custom format designed for minimal overhead. | | [`local`](local.md) | Logs are stored in a custom format designed for minimal overhead. |
| [`json-file`](json-file.md) | The logs are formatted as JSON. The default logging driver for Docker. | | [`json-file`](json-file.md) | The logs are formatted as JSON. The default logging driver for Docker. |
| [`syslog`](syslog.md) | Writes logging messages to the `syslog` facility. The `syslog` daemon must be running on the host machine. | | [`syslog`](syslog.md) | Writes logging messages to the `syslog` facility. The `syslog` daemon must be running on the host machine. |
| [`journald`](journald.md) | Writes log messages to `journald`. The `journald` daemon must be running on the host machine. | | [`journald`](journald.md) | Writes log messages to `journald`. The `journald` daemon must be running on the host machine. |
| [`gelf`](gelf.md) | Writes log messages to a Graylog Extended Log Format (GELF) endpoint such as Graylog or Logstash. | | [`gelf`](gelf.md) | Writes log messages to a Graylog Extended Log Format (GELF) endpoint such as Graylog or Logstash. |
| [`fluentd`](fluentd.md) | Writes log messages to `fluentd` (forward input). The `fluentd` daemon must be running on the host machine. | | [`fluentd`](fluentd.md) | Writes log messages to `fluentd` (forward input). The `fluentd` daemon must be running on the host machine. |
| [`awslogs`](awslogs.md) | Writes log messages to Amazon CloudWatch Logs. | | [`awslogs`](awslogs.md) | Writes log messages to Amazon CloudWatch Logs. |
| [`splunk`](splunk.md) | Writes log messages to `splunk` using the HTTP Event Collector. | | [`splunk`](splunk.md) | Writes log messages to `splunk` using the HTTP Event Collector. |
| [`etwlogs`](etwlogs.md) | Writes log messages as Event Tracing for Windows (ETW) events. Only available on Windows platforms. | | [`etwlogs`](etwlogs.md) | Writes log messages as Event Tracing for Windows (ETW) events. Only available on Windows platforms. |
| [`gcplogs`](gcplogs.md) | Writes log messages to Google Cloud Platform (GCP) Logging. | | [`gcplogs`](gcplogs.md) | Writes log messages to Google Cloud Platform (GCP) Logging. |
| [`logentries`](logentries.md) | Writes log messages to Rapid7 Logentries. | | [`logentries`](logentries.md) | Writes log messages to Rapid7 Logentries. |
> **Note** > **Note**
> >
> When using Docker Engine 19.03 or older, the [`docker logs` command](../../../engine/reference/commandline/logs.md) > When using Docker Engine 19.03 or older, the [`docker logs` command](../../../engine/reference/commandline/logs.md)
> is only functional for the `local`, `json-file` and `journald` logging drivers. > is only functional for the `local`, `json-file` and `journald` logging drivers.
> Docker 20.10 and up introduces "dual logging", which uses a local buffer that > Docker 20.10 and up introduces "dual logging", which uses a local buffer that
> allows you to use the `docker logs` command for any logging driver. Refer to > allows you to use the `docker logs` command for any logging driver. Refer to
> [reading logs when using remote logging drivers](dual-logging.md) for details. > [reading logs when using remote logging drivers](dual-logging.md) for details.
## Limitations of logging drivers ## Limitations of logging drivers
- Reading log information requires decompressing rotated log files, which causes - Reading log information requires decompressing rotated log files, which causes
a temporary increase in disk usage (until the log entries from the rotated a temporary increase in disk usage (until the log entries from the rotated
files are read) and an increased CPU usage while decompressing. files are read) and an increased CPU usage while decompressing.
- The capacity of the host storage where the Docker data directory resides - The capacity of the host storage where the Docker data directory resides
determines the maximum size of the log file information. determines the maximum size of the log file information.