将容器日志发送到 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_(设计模式)单例模式

    菜鸟教程 传送门 单例模式(Singleton Pattern)是 Java 中最简单的设计模式之一.这种类型的设计模式属于创建型模式,它提供了一种创建对象的最佳方式. 这种模式涉及到一个单一的类,该 ...

  2. springboot 测试发送邮件

    首先在pom文件引入依赖: <!--email依赖 --> <dependency> <groupId>org.springframework.boot</g ...

  3. ValueError: Unable to determine SOCKS version from socks://127.0.0.1:1080/

    使用ss之后输入conda指令出现错误:“ValueError: Unable to determine SOCKS version from socks://127.0.0.1:1080/”. 解决 ...

  4. vue开发多页面应用

    1.添加多页面配置 在工程根路径下(package.json同目录)添加添加vue.config.js配置文件,内容为: module.exports = { pages: { index: 'src ...

  5. Mysql超强卸载

    1.控制面板——>所有控制面板项——>程序和功能,卸载mysql server! 2.删除MySQL文件,尤其是ProgramData里面的隐藏文件MySQL,我当时没有删除,重新安装My ...

  6. iframe标签的初试

    要使用的框架的页面代码: <body> <form id="form1" runat="server"> <div> < ...

  7. weblogic报:java.lang.LinkageError: loader constraint violation in interface itable initialization

    原因分析: gdaml服务中依赖org.apache.xerces_2.9.0.v201101211617.jar会产生jar包冲突 解决方法: 项目中的这个jar包删除,并将这个jar包放在服务器中 ...

  8. web安全之如何防止CSRF跨站请求伪造(转载)

    https://www.cnblogs.com/blibli/p/7658168.html CSRF(Cross-site request forgery)跨站请求伪造,也被称为“One Click ...

  9. MethodChannel 实现flutter 与 原生通信

    Flutter 步骤 目的:在flutter页面中主动调用原生页面中的方法. 1 在widget中,定义MethodChannel变量 static const MethodChannel metho ...

  10. Dark 面向对象

    1 继承 使用extends继承一个类 子类会继承父类可见的属性和方法,不包含构造方法 可以复写父类的方法 单继承,多态性 构造方法 子类的构造方法会默认调用父类的无名无参构造方法 如果父类没有无名无 ...