1. 日志驱动
Docker包括多种容器日志记录方式,这个机制又叫做logging drivers。logging driver经常在配置在Docker 守护进程级别,默认的logging driver是json-file. 还支持以下几种级别
Driver | Description |
---|---|
none | No logs are available for the container and docker logs does not return any output. |
local | Logs are stored in a custom format designed for minimal overhead. |
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. |
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