Docker,Supervisord和日志logging – 如何整合docker日志中的日志?

所以,通过uWSGI来试验Docker + Supervisord + Django应用程序。 我有整个工作正常,但需要整理日志logging。

如果我以非守护模式启动主pipe,

/usr/bin/supervisord -n 

然后我得到了监督日志标准输出的日志输出。 但是,如果supervisord处于守护进程模式,则它自己的日志将被隐藏在容器文件系统中,并且其应用程序的日志也会在自己的app_stderr / stdout文件中执行。

我想要的是将pipe理员和应用程序标准输出logging到docker日志中。

在非守护模式下启动supervisord是一个合理的想法,还是会造成意想不到的后果? 另外,我怎样才能获得应用程序日志也发挥到docker日志?

我同意,不使用守护进程模式听起来像是最好的解决scheme,但我可能会采用与实际的物理服务器或某种虚拟机设置相同的策略:集中logging。

您可以在容器内使用像logstash这样的自托pipe来收集日志并将其发送到中央服务器。 或者使用像loggly或papertrail这样的商业服务来做同样的事情。

我完成了这个使用。

在你的Docker镜像中安装supervisor-stdout :

 RUN apt-get install -y python-pip && pip install supervisor-stdout 

Supervisordconfiguration

编辑你的supervisord.conf如下所示:

 [program:myprogram] command=/what/ever/command stdout_events_enabled=true stderr_events_enabled=true [eventlistener:stdout] command = supervisor_stdout buffer_size = 100 events = PROCESS_LOG result_handler = supervisor_stdout:event_handler 

Docker容器就像一个kleenex,你使用它然后把它放下。 为了“活着”,Docker需要在前台运行(而守护进程在后台运行),这就是为什么你使用Supervisord。

所以你需要“redirect/添加/合并”过程输出(访问和错误)到运行你的容器时看到的Supervisord输出。

正如德鲁所说,每个人都使用https://github.com/coderanger/supervisor-stdout来实现它(对我来说,这应该被添加到supervisord项目!)。 德鲁忘了说了,你可能需要补充

 stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 

到supervisord程序configuration块。

还有一点非常有用,假设你的进程正在login一个日志文件而不是stdout,你可以问supervisord看看它:

 [program:php-fpm-log] command=tail -f /var/log/php5-fpm.log stdout_events_enabled=true stderr_events_enabled=true 

这将通过supervisord-stdout将php5-fpm.log内容redirect到stdout,然后redirect到supervisord stdout。

supervisor-stdout需要安装python-pip,下载约150MB,对于一个容器,我认为很多只是为了安装另一个工具。

将日志文件redirect到/ dev / stdout适用于我:

 stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 

http://veithen.github.io/2015/01/08/supervisord-redirecting-stdout.html

今天最好的做法是拥有最小的Docker镜像。 对于我来说,使用Python应用程序的理想容器只包含我的代码,支持库和类似uwsgi东西,如果有必要的话。

我在https://github.com/msgre/uwsgi_logging上发布了一个解决scheme。 这是简单的Django应用程序后面的uwsgi ,它被configuration为显示来自uwsgi和Django应用程序的容器标准输出日志,而不需要supervisor

事实上,以非守护模式启动supervisord是最好的解决scheme。

您也可以使用卷来将supervisord的日志安装到中心位置。