将容器日志发送到 STDOUT 和 STDERR 是Docker 的默认日志行为。实际上,Docker提供了多种日志机制帮助用户从运行的容器中提取日志信息。这些机制被称作logging driver 。
 
Docker 的默认 logging driver 是 json-file
 
root@host1:~# docker info | grep 'Logging Driver'
Logging Driver: json-file
 
如果容器在启动时没有特别指明,就会使用这个默认的 logging driver。
 
json-file 会将容器的日志保存在json文件中,Docker 负责格式化其内容并输出到 STDOUT 和 STDERR
 
我们可以在 Host 的容器目录中找到这个文件,日志的位置在
 
[root@ubuntu ~]# docker inspect web03 | jq .[].HostConfig.LogConfig
{
  "Type": "json-file",
  "Config": {}
}
[root@ubuntu ~]# docker inspect web03 | jq .[].LogPath
"/var/lib/docker/containers/d777fe241f27b541a776e4e0eca4e86754e61d7fe324bb6720e46711707a5a30/d777fe241f27b541a776e4e0eca4e86754e61d7fe324bb6720e46711707a5a30-json.log"
 
比如我们看之前httpd容器的json格式的日志文件。
 
[root@ubuntu ~]# docker logs web03
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.4. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.4. Set the 'ServerName' directive globally to suppress this message
[Thu May 09 01:07:37.761772 2019] [mpm_event:notice] [pid 1:tid 140651667042368] AH00489: Apache/2.4.39 (Unix) configured -- resuming normal operations
[Thu May 09 01:07:37.761911 2019] [core:notice] [pid 1:tid 140651667042368] AH00094: Command line: 'httpd -D FOREGROUND'
10.12.28.253 - - [09/May/2019:01:07:44 +0000] "GET /httpd_access_testweb03 HTTP/1.1" 404 220
10.12.28.253 - - [09/May/2019:01:08:09 +0000] "GET /httpd_access_testweb03 HTTP/1.1" 404 220
10.12.28.253 - - [09/May/2019:01:08:09 +0000] "GET /httpd_access_testweb03 HTTP/1.1" 404 220
10.12.28.253 - - [09/May/2019:01:08:11 +0000] "GET /httpd_access_testweb03_01 HTTP/1.1" 404 223
10.12.28.253 - - [09/May/2019:01:08:12 +0000] "GET /httpd_access_testweb03_02 HTTP/1.1" 404 223
10.12.28.253 - - [09/May/2019:01:08:13 +0000] "GET /httpd_access_testweb03_03 HTTP/1.1" 404 223
 
[root@ubuntu ~]# docker inspect web03 | jq .[].LogPath
"/var/lib/docker/containers/d777fe241f27b541a776e4e0eca4e86754e61d7fe324bb6720e46711707a5a30/d777fe241f27b541a776e4e0eca4e86754e61d7fe324bb6720e46711707a5a30-json.log"
 
[root@ubuntu ~]# cat /var/lib/docker/containers/d777fe241f27b541a776e4e0eca4e86754e61d7fe324bb6720e46711707a5a30/d777fe241f27b541a776e4e0eca4e86754e61d7fe324bb6720e46711707a5a30-json.log
{"log":"AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.4. Set the 'ServerName' directive globally to suppress this message\n","stream":"stderr","time":"2019-05-09T01:07:37.757312662Z"}
{"log":"AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.4. Set the 'ServerName' directive globally to suppress this message\n","stream":"stderr","time":"2019-05-09T01:07:37.760288136Z"}
{"log":"[Thu May 09 01:07:37.761772 2019] [mpm_event:notice] [pid 1:tid 140651667042368] AH00489: Apache/2.4.39 (Unix) configured -- resuming normal operations\n","stream":"stderr","time":"2019-05-09T01:07:37.761957452Z"}
{"log":"[Thu May 09 01:07:37.761911 2019] [core:notice] [pid 1:tid 140651667042368] AH00094: Command line: 'httpd -D FOREGROUND'\n","stream":"stderr","time":"2019-05-09T01:07:37.76197126Z"}
{"log":"10.12.28.253 - - [09/May/2019:01:07:44 +0000] \"GET /httpd_access_testweb03 HTTP/1.1\" 404 220\n","stream":"stdout","time":"2019-05-09T01:07:44.448412013Z"}
{"log":"10.12.28.253 - - [09/May/2019:01:08:09 +0000] \"GET /httpd_access_testweb03 HTTP/1.1\" 404 220\n","stream":"stdout","time":"2019-05-09T01:08:09.313879068Z"}
{"log":"10.12.28.253 - - [09/May/2019:01:08:09 +0000] \"GET /httpd_access_testweb03 HTTP/1.1\" 404 220\n","stream":"stdout","time":"2019-05-09T01:08:09.94122045Z"}
{"log":"10.12.28.253 - - [09/May/2019:01:08:11 +0000] \"GET /httpd_access_testweb03_01 HTTP/1.1\" 404 223\n","stream":"stdout","time":"2019-05-09T01:08:11.813695979Z"}
{"log":"10.12.28.253 - - [09/May/2019:01:08:12 +0000] \"GET /httpd_access_testweb03_02 HTTP/1.1\" 404 223\n","stream":"stdout","time":"2019-05-09T01:08:12.723122224Z"}
{"log":"10.12.28.253 - - [09/May/2019:01:08:13 +0000] \"GET /httpd_access_testweb03_03 HTTP/1.1\" 404 223\n","stream":"stdout","time":"2019-05-09T01:08:13.813166874Z"}
 
 
除了 json-file ,Docker 还支持多种 logging driver 。完成的列表可以访问docker官方网站查询 https://docs.docker.com/config/containers/logging/configure/#supported-logging-drivers
 
 
none 是disable 容器日志功能
 
syslogs 和 journald 是linux上两种日志管理服务
 
awslogs 、 splunk 和 gcplogs 是第三方日志托管服务
 
gelf 和 fluentd 是两种开源的日志管理方案
 
容器在启动时可以通过 --log-driver 指定使用的logging driver 。如果要设置Docker 默认的 logging driver ,需要修改 Docker daemon 的启动脚本,指定 --log-driver 参数,比如下面,每种 logging driver 都有自己的 --log-opt ,用的时候去官网查询即可
 
ExecStart=/usr/bin/dockerd -H fd:// --log-driver=syslog --log-opt ......
 
 

088、Docker 如何支持多种日志方案 (2019-05-10 周五)的更多相关文章

  1. Docker 如何支持多种日志方案?- 每天5分钟玩转 Docker 容器技术(88)

    将容器日志发送到 STDOUT 和 STDERR 是 Docker 的默认日志行为.实际上,Docker 提供了多种日志机制帮助用户从运行的容器中提取日志信息.这些机制被称作 logging driv ...

  2. docker 日志方案

    docker logs默认会显示命令的标准输出(STDOUT)和标准错误(STDERR).下面使用echo.sh和Dockerfile创建一个名为echo.v1的镜像,echo.sh会一直输出”hel ...

  3. centos7下安装docker(18.1docker日志---logging driver)

    将容器的日志发送到STDOUT和STDERR是docker的默认日志行为.实际上,docker提供了多种日志机制帮助用户从容器中提取日志,这些机制被称为logging driver docker的默认 ...

  4. StreamSets学习系列之StreamSets支持多种安装方式【Core Tarball、Cloudera Parcel 、Full Tarball 、Full RPM 、Docker Image和Source Code 】(图文详解)

    不多说,直接上干货! Streamsets的官网 https://streamsets.com/ 得到 https://streamsets.com/opensource/ StreamSets支持多 ...

  5. centos7下安装docker(18.2docker日志---ELK)

    ELK是三个软件得组合:Elasticsearch,Logstash,Kibana Elasticsearch:实时查询的全文搜索引擎.Elasticsearch的设计目的就是能够处理和搜索巨量的日志 ...

  6. Kubernetes 集群日志 和 EFK 架构日志方案

    目录 第一部分:Kubernetes 日志 Kubernetes Logging 是如何工作的 Kubernetes Pod 日志存储位置 Kubelet Logs Kubernetes 容器日志格式 ...

  7. 莱特币ltc在linux下的多种挖矿方案详解

    莱特币ltc在linux下的多种挖矿方案详解 4.0.1 Nvidia显卡Linux驱动Nvidia全部驱动:http://www.nvidia.cn/Download/index.aspx?lang ...

  8. Kubernetes审计日志方案

    前言 当前Kubernetes(K8S)已经成为事实上的容器编排标准,大家关注的重点也不再是最新发布的功能.稳定性提升等,正如Kubernetes项目创始人和维护者谈到,Kubernetes已经不再是 ...

  9. 0x04 Python logger 支持多进程日志按大小分割

    目录 支持多进程日志按大小分割 多进程日志大小分割handler配置实例 支持多进程日志按大小分割 由于python内置模块logging.handlers.RotatingFileHandler是不 ...

随机推荐

  1. JavaWeb_(Jar)使用fastjson解析json和序列化对象

    菜鸟教程 传送门 JSON官网 传送门 fastjson插件下载 传送门 序列化[百度百科]:序列化 (Serialization)是将对象的状态信息转换为可以存储或传输的形式的过程.在序列化期间,对 ...

  2. C++入门经典-例6.18-数组的动态分配,动态获得斐波那契数列

    1:有时在获得一定的信息之前,我们并不确定数组的大小.动态分配数组则可以使用变量作为数组的大小,使数组的大小符合我们的要求. 2:科普一下斐波纳契数列:斐波那契数列指的是这样一个数列 1, 1, 2, ...

  3. 自定义实现Java动态代理

    转自:https://www.cnblogs.com/rjzheng/p/8750265.html 一 借助JDK的API实现: 1.先创建一个接口,并实现它 public interface Per ...

  4. TreeMap元素必须实现Comparable接口

    纠正一下,TreeMap实现一定顺序是通过Comparable接口的,而他实现元素不重复也是完全通过compareTo,而不是hashCode和equals,因为debug不会走到hashCode和e ...

  5. jQuery file upload --Multiple File Input Fields in One Form

    The plugin can be applied to a form with multiple file input fields out of the box. The files are se ...

  6. Xmanager power suit 6 最新版注册激活附注册机

    转自:https://blog.csdn.net/the_liang/article/details/82708907 Xmanager Power Suit 6.0.0109 最新版注册激活,长期更 ...

  7. lnmp 环境下 部署 laravel 项目

    出现错误 Warning: require(): open_basedir restriction in effect. File(/xxxx/vendor/autoload.php) is not ...

  8. Gin框架中文文档

    Gin 是一个 go 写的 web 框架,具有高性能的优点.官方地址:https://github.com/gin-gonic/gin 带目录请移步 http://xf.shuangdeyu.com/ ...

  9. 安装docker registry

    docker pull registry 创建目录  /usr/local/docker/registry 创建 docker-compose.yml version: '3' services: r ...

  10. 换根dp特征总结

    Rt,大概总结一下吧(不时更新一小下 1.一般都没有指定根,刚开始随便选一个根(1号点工具人) 2.两次$dfs$,一次从工具人开始预处理一些东西,第二次(也是从工具人开始)换根. 3.多用于:只要确 ...