docker日志驱动程序

docker日志驱动程序

本文介绍了docker日志驱动程序"json-file"滚动更新时日志丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果max-file值设置为2,则将创建两个文件,如下所示.

If the max-file value is set to 2, two files are created as shown below.

11111-json.log
11111-json.log.1

但是在这里,当11111-json.log文件大小为max-size时,11111-json.log的内容将移动到11111-json.log.1,并且11111-json.log的大小变为零./var/log/容器此时,我丢失了最后一条日志.

But here, when the 11111-json.log file size is max-size, the contents of 11111-json.log are moved to 11111-json.log.1, and the size of 11111-json.log Becomes zero./var/log/containerAt this point I lose the last log.

/var/log/container路径中的日志最终链接到/var/lib/docker/containers/~,因此,如果上述文件以这种方式工作,该日志将丢失.

The log in the /var/log/container path eventually links to /var/lib/docker/containers/~, so if the file mentioned above works that way, the log will be lost.

我怎么不迷路?

推荐答案

根据您的设置,所有日志.log.1,.log.2都存储在/var/lib/docker/containers/...中,并以根据docker文档,您可以在 daemon.json 中更改docker的那些设置:

According to your settings, all logs .log.1, .log.2 are stored in /var/lib/docker/containers/... and as per docker documentation you can change those settings for docker in daemon.json:

 "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3",

在/var/log/containers中,您可以找到指向最后创建的日志文件的链接.

in /var/log/containers you can find link to the last created log file.

根据 flunetd 的文档:您应该考虑使用 in_tail 选项:

As per documentation for flunetd:You should consider using in_tail option:

请参阅类似的社区帖子

这篇关于docker日志驱动程序"json-file"滚动更新时日志丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 19:42