Docker Log

Intoduction

Docker容器在默认情况下会将打印到stdout、stderr的日志数据存储在本地磁盘上,默认位置为/var/lib/docker/containers/{ContainerId} /{ContainerId}-json.log。

Driver

  • none:No logs are available for the container and docker logs does not return any output.
  • json-file:The logs are formatted as JSON. The default logging driver for Docker.
  • syslog:Writes logging messages to the syslog facility. The syslog daemon must be running on the host machine.
  • journald:Writes log messages to journald. The journald daemon must be running on the host machine.
  • gelf:Writes log messages to a Graylog Extended Log Format (GELF) endpoint such as Graylog or Logstash.
  • fluentd:Writes log messages to fluentd (forward input). The fluentd daemon must be running on the host machine.
  • awslogs:Writes log messages to Amazon CloudWatch Logs.
  • splunk:Writes log messages to splunk using the HTTP Event Collector.
  • etwlogs:Writes log messages as Event Tracing for Windows (ETW) events. Only available on Windows platforms.
  • gcplogs:Writes log messages to Google Cloud Platform (GCP) Logging.
  • logentries:Writes log messages to Rapid7 Logentries.

Usage

1
2
3
docker run \
--log-driver json-file --log-opt max-size=10m \
alpine echo hello world