将容器日志发送到 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. opencv_将图像上的4个点按逆时针排序

    1:代码如下: #include "stdafx.h" #include "cxcore.h" #include "cvcam.h" #in ...

  2. ubuntu环境配置终极解答

    1. ubuntu中常用的5个配置文件 1)/etc/profile 2)/etc/environment 环境变量在这个文件中定义,可以用vim /etc/environment查看该文件内容 3) ...

  3. docker—tomcat 报错:Failed to get D-Bus connection: Operation not permitted

    docker search centos   查系统镜像 docker pull docker.io/centos 进入容器 [root@git opt]# docker images REPOSIT ...

  4. WIN10下命令行禁用编辑模式

    在开发的时候 控制台输出信息 点一下右键就进入编辑模式了,WIN7没有这个问题.网上搜了一下 说是要 禁用编辑模式,下面是代码VS2005可用 { #ifndef ENABLE_EXTENDED_FL ...

  5. leetcode-easy-string-28 Implement strStr()

    mycode   77.15% class Solution(object): def strStr(self, haystack, needle): """ :type ...

  6. spring boot统一异常页面

    只需要创建一个类就可以了 package com.ulic.gis.securityManage.controller; import java.util.Map; import javax.serv ...

  7. ControlTemplate in WPF —— TreeView

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x ...

  8. java: (正则表达式,XML文档,DOM和DOM4J解析方法)

    常见的XML解析技术: 1.DOM(基于XML树结构,比较耗资源,适用于多次访问XML): 2.SAX(基于事件,消耗资源小,适用于数量较大的XML): 3.JDOM(比DOM更快,JDOM仅使用具体 ...

  9. 关于token的理解

    什么是token token的意思是“令牌”,是服务端生成的一串字符串,作为客户端进行请求的一个标识. 当用户第一次登录后,服务器生成一个token并将此token返回给客户端,以后客户端只需带上这个 ...

  10. 【HANA系列】SAP HANA跟我学HANA系列之创建属性视图一

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA跟我学HANA系 ...