Use docker logs with remote logging drivers (original) (raw)

You can use the docker logs command to read container logs regardless of the configured logging driver or plugin. Docker Engine uses thelocallogging driver to act as cache for reading the latest logs of your containers. This is called dual logging. By default, the cache has log-file rotation enabled, and is limited to a maximum of 5 files of 20 MB each (before compression) per container.

Refer to theconfiguration options section to customize these defaults, or to thedisable dual loggingsection to disable this feature.

Docker Engine automatically enables dual logging if the configured logging driver doesn't support reading logs.

The following examples show the result of running a docker logs command with and without dual logging availability:

Without dual logging capability

When a container is configured with a remote logging driver such as splunk, and dual logging is disabled, an error is displayed when attempting to read container logs locally:

With dual logging capability

With the dual logging cache enabled, the docker logs command can be used to read logs, even if the logging driver doesn't support reading logs. The following example shows a daemon configuration that uses the splunk remote logging driver as a default, with dual logging caching enabled:

Note

For logging drivers that support reading logs, such as the local, json-fileand journald drivers, there is no difference in functionality before or after the dual logging capability became available. For these drivers, Logs can be read using docker logs in both scenarios.

Configuration options

The dual logging cache accepts the same configuration options as thelocal logging driver, but with a cache- prefix. These options can be specified per container, and defaults for new containers can be set using thedaemon configuration file.

By default, the cache has log-file rotation enabled, and is limited to a maximum of 5 files of 20MB each (before compression) per container. Use the configuration options described below to customize these defaults.

Option Default Description
cache-disabled "false" Disable local caching. Boolean value passed as a string (true, 1, 0, or false).
cache-max-size "20m" The maximum size of the cache before it is rotated. A positive integer plus a modifier representing the unit of measure (k, m, or g).
cache-max-file "5" The maximum number of cache files that can be present. If rotating the logs creates excess files, the oldest file is removed. A positive integer.
cache-compress "true" Enable or disable compression of rotated log files. Boolean value passed as a string (true, 1, 0, or false).

Use the cache-disabled option to disable the dual logging cache. Disabling the cache can be useful to save storage space in situations where logs are only read through a remote logging system, and if there is no need to read logs throughdocker logs for debugging purposes.

Caching can be disabled for individual containers or by default for new containers, when using thedaemon configuration file.

The following example uses the daemon configuration file to use thesplunklogging driver as a default, with caching disabled:

Note

For logging drivers that support reading logs, such as the local, json-fileand journald drivers, dual logging isn't used, and disabling the option has no effect.