Skip to content

1. 日志驱动

Docker包括多种容器日志记录方式,这个机制又叫做logging drivers。logging driver经常在配置在Docker 守护进程级别,默认的logging driver是json-file. 还支持以下几种级别

DriverDescription
noneNo logs are available for the container and docker logs does not return any output.
localLogs are stored in a custom format designed for minimal overhead.
json-fileThe logs are formatted as JSON. The default logging driver for Docker.
syslogWrites logging messages to the syslog facility. The syslog daemon must be running on the host machine.
journaldWrites log messages to journald. The journald daemon must be running on the host machine.
gelfWrites log messages to a Graylog Extended Log Format (GELF) endpoint such as Graylog or Logstash.

1.1 查看

bash
 #查看全局
 docker info --format '{{.LoggingDriver}}'
 
 #查看单独
 docker inspect -f '{{.HostConfig.LogConfig.Type}}' CONTAINER
 #查看全局
 docker info --format '{{.LoggingDriver}}'
 
 #查看单独
 docker inspect -f '{{.HostConfig.LogConfig.Type}}' CONTAINER

1.2 模式

1.none

bash
docker container run --name none_logging_driver -it --log-driver none busybox sh -c 'for N in 1 2 3; do echo "Hello $N"; done'

cd /var/lib/docker/containers/$(docker ps --no-trunc -aqf "name=none_logging_driver")

docker logs none_logging_driver
Error response from daemon: configured logging driver does not support reading
docker container run --name none_logging_driver -it --log-driver none busybox sh -c 'for N in 1 2 3; do echo "Hello $N"; done'

cd /var/lib/docker/containers/$(docker ps --no-trunc -aqf "name=none_logging_driver")

docker logs none_logging_driver
Error response from daemon: configured logging driver does not support reading

官当