非常教程

Docker 17参考手册

引擎: 管理员指南 | Engine: Admin Guide

Journald日志记录驱动程序(引擎) | Journald logging driver (Engine)

journald日志驱动程序将容器日志发送到systemd日刊.日志条目可以使用journalctl命令,通过使用journalAPI,或使用docker logs命令。

除了日志消息本身的文本之外,journald日志驱动程序将以下元数据与每条消息一起存储在日记中:

Field

Description

CONTAINER_ID

The container ID truncated to 12 characters.

CONTAINER_ID_FULL

The full 64-character container ID.

CONTAINER_NAME

The container name at the time it was started. If you use docker rename to rename a container, the new name is not reflected in the journal entries.

CONTAINER_TAG

The container tag (log tag option documentation).

CONTAINER_PARTIAL_MESSAGE

A field that flags log integrity. Improve logging of long log lines.

使用

使用journald驱动程序作为默认日志记录驱动程序,设置log-driverlog-opt控件中的适当值的键。daemon.json文件,该文件位于/etc/docker/在linux主机上或C:\ProgramData\docker\config\daemon.json在WindowsServer上。有关+配置Docker的更多信息,请使用daemon.json,见+daemon.json...

下面的示例将日志驱动程序设置为journald*

{
  "log-driver": "journald"
}

重新启动Docker以使更改生效。

若要为特定容器配置日志驱动程序,请使用--log-driver标志上docker run命令。

$ docker run --log-driver=journald ...

备选方案

使用--log-opt NAME=VALUE标志指定附加journald日志驱动程序选项。

tag

指定要设置的模板CONTAINER_TAG价值journald原木。请参阅日志标记选项文档若要自定义日志标记格式,请执行以下操作。

labels,,,env,和eng-regex

labelsenv每个选项都采用逗号分隔的键列表。如果有碰撞labelenv键的值。env优先考虑。每个选项都会向日记中添加附加元数据和每条消息。

env-regexenv.将其设置为正则表达式以匹配与日志记录相关的环境变量.。它用于高级日志标记选项...

关于容器名称的说明

中记录的值。CONTAINER_NAME字段是在启动时设置的容器的名称。如果你用docker rename若要重命名容器,请使用新名称未反映在日记里。日记账条目将继续使用原始名称。

检索日志消息journalctl

使用journalctl命令检索日志消息。可以应用筛选器表达式将检索到的消息限制为与特定容器关联的消息:

$ sudo journalctl CONTAINER_NAME=webserver

您可以使用其他筛选器进一步限制检索的消息。大-b标志仅检索上次系统启动后生成的消息:

$ sudo journalctl -b CONTAINER_NAME=webserver

-o标志指定重试日志消息的格式。使用-o json返回JSON格式的日志消息。

$ sudo journalctl -o json CONTAINER_NAME=webserver

检索日志消息。journalAPI

此示例使用systemd用于检索容器日志的Python模块:

import systemd.journal

reader = systemd.journal.Reader()
reader.add_match('CONTAINER_NAME=web')

    for msg in reader:
      print '{CONTAINER_ID_FULL}: {MESSAGE}'.format(**msg)

期刊,码头工人,测井,司机

引擎: 管理员指南 | Engine: Admin Guide相关

1.Amazon CloudWatch记录日志记录驱动程序(引擎) | Amazon CloudWatch logs logging driver (Engine)
2. 绑定挂载 | Bind mounts (Engine)
3.使用Prometheus(引擎)收集Docker指标 | Collect Docker metrics with Prometheus (Engine)
4.配置和运行Docker(引擎) | Configuring and running Docker (Engine)
5.配置日志记录驱动程序 | Configuring logging drivers (Engine)
6.使用systemd控制和配置Docker(引擎) | Control and configure Docker with systemd (Engine)
7.ETW日志记录驱动程序(引擎) | ETW logging driver (Engine)
8.流利的日志驱动程序(引擎) | Fluentd logging driver (Engine)
9.格式化命令和日志输出(引擎) | Format command and log output (Engine)
10.Google Cloud日志记录驱动程序(引擎) | Google Cloud logging driver (Engine)
11.Graylog扩展格式(GELF)日志记录驱动程序(引擎) | Graylog Extended Format (GELF) logging driver (Engine)
12.JSON文件日志记录驱动程序(引擎) | JSON File logging driver (Engine)
13.在守护进程停机期间保持容器处于活动状态(引擎) | Keep containers alive during daemon downtime (Engine)
14.限制容器的资源(引擎) | Limit a container's resources (Engine)
15.通过大使容器链接(引擎) | Link via an ambassador container (Engine)
16.记录驱动程序的日志标记(引擎) | Log tags for logging driver (Engine)
17.Logentries日志驱动程序(引擎) | Logentries logging driver (Engine)
18.PowerShell DSC用法(引擎) | PowerShell DSC usage (Engine)
19.修剪未使用的Docker对象(引擎) | Prune unused Docker objects (Engine)
20.在容器中运行多个服务(引擎) | Run multiple services in a container (Engine)
21.运行时指标(引擎) | Runtime metrics (Engine)
22.Splunk日志记录驱动程序(引擎) | Splunk logging driver (Engine)
23.自动启动容器(引擎) | Start containers automatically (Engine)
24.存储概述(引擎) | Storage overview (Engine)
25.Syslog日志记录驱动程序(引擎) | Syslog logging driver (Engine)
26.tmpfs mounts
27.解决卷问题(引擎) | Troubleshoot volume problems (Engine)
28.使用日志驱动程序插件(引擎) | Use a logging driver plugin (Engine)
29.使用Ansible(引擎) | Using Ansible (Engine)
30.使用Chef(引擎) | Using Chef (Engine)
31.使用Puppet(引擎) | Using Puppet (Engine)
32.查看容器的日志(引擎) | View a container's logs (Engine)
33.Volumes (Engine)
Docker 17

Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。

主页 https://docker.com/
源码 https://github.com/docker/docker
版本 17
发布版本 17.06