2017-04-01 47 views

回答

3

通常的做法是容器内的应用程序不会登录到文件,但输出日志stdout/stderr。容器的主要过程打印到stdout/stderr的任何内容都由码头工人的内置记录设施收集,可以使用docker logs <container-name>查看。

默认情况下,日志存储在每个容器使用json-file登录驱动程序,当容器本身被删除将被删除,但也有其他的日志记录程序(请参阅Configure logging drivers),让您的日志发送到(例如)syslog,journald,gelf

另见

+0

如果您发送的PHP日志(如应用程序日志)到stdout,他们将HTTP响应发送里面。也许有一种方法可以将他们的stderr发送到php-fpm stderr或类似的地方。 – giorgiosironi

+0

@giorgiosironi这里是官方的php-fpm图像如何处理它; https://github.com/docker-library/php/blob/f795769559d9ce740e57ebd32f60f8a4569ee5b6/7.2/stretch/fpm/Dockerfile#L181-L186 – thaJeztah

+0

谢谢,但遇到https://github.com/php/php-src/pull/1076因此我放弃了stderr方法,因为JSON日志受到'php-fpm'引入的换行符和其他注释的干扰或损坏。 – giorgiosironi

0

为Docker容器的标准是记录到stdout/stderr。但是,这对于某些PHP运行时无法正常工作,例如php-fpm,因为日志在lengthformat中被损坏。

因此,我将我的方法转换为在卷上写入日志,并使用sidecar container将它转换为stderr,然后放入Docker的日志收集器和/或您的编排器中。

样品docker-compose.yml部分:

cli: 
    build: . 
    volumes: 
     - logs:/srv/annotations/var/logs 
logger: 
    image: busybox:1.27.2 
    volumes: 
     - logs:/logs 
    # be careful, this will only tail alredy existing files 
    command: tail -f /logs/all.json 
    depends_on: 
     - cli 
相关问题