如何在Docker容器中使用Apache,并且什么都不写入磁盘(所有日志到STDIO / STDERR)? [英] How does one use Apache in a Docker Container and write nothing to disk (all logs to STDIO / STDERR)?

查看:429
本文介绍了如何在Docker容器中使用Apache,并且什么都不写入磁盘(所有日志到STDIO / STDERR)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Docker容器中运行Apache2,并且不想对磁盘写入任何内容,将日志写入stdout和stderr。我已经看到了几种不同的方法(Supervisord和stdout / stderr,Apache访问stdout),但这些似乎是黑客。没有办法默认这样做?



要清楚,我不想拖尾日志,因为这将导致写入磁盘的东西容器。



官方版本检入Docker Hub( https://hub.docker.com/_/httpd/ )仍然写入磁盘。



此外,我需要什么在尝试滚动日志时,要阻止Apache发生故障吗?



另一件事 - 理想情况下,我真的很想这样做,而不需要另外一个加载项。 nginx可以这样做。

解决方案

根据apache邮件列表,你可以直接写入/ dev / stdio Unix喜欢系统),因为这只是一个常规的文件句柄。简单!粘贴...


最有效的答案取决于您的操作系统。如果您在UNIX系统上提供
,该系统提供/ dev / stdout和/ dev / stderr(或
或/ dev / fd / 1和/ dev / fd / 2),则使用这些文件名。如果
不是一个选项,使用管道输出功能。例如,从我的
配置:



CustomLog| / usr / sbin / rotatelogs -c -f -l -L
/ private / var / log / apache2 / test-access.log
/private/var/log/apache2/test-access.log.%Y-%m-%d 86400
krader_custom ErrorLog| / usr / sbin / rotatelogs -c -f -l -L
/private/var/log/apache2/test-error.log
/private/var/log/apache2/test-error.log.% Y-%m-%d 86400



显然,您将要替换另一个程序
/ usr / sbin / rotatelogs在上面的例子中写
你想要的数据。


https://mail-archives.apache。 org / mod_mbox/httpd-users/201508.mbox/%3CCABx2=D-wdd8FYLkHMqiNOKmOaNYb-tAOB-AsSEf2p=ctd6sMdg@mail.gmail.com%3E


I'm running Apache2 in a docker container and want to write nothing to the disk, writing logs to stdout and stderr. I've seen a few different ways to do this (Supervisord and stdout/stderr, Apache access log to stdout) but these seem like hacks. Is there no way to do this by default?

To be clear, I do not want to tail the log, since that will result in things being written to the disk in the container.

The "official" version checked into Docker Hub (https://hub.docker.com/_/httpd/) still write to disk.

Also, what do I need to do to stop Apache from failing when it tries to roll the logs?

One other thing - ideally, I'd really like to do this without another add-on. nginx can do this trivially.

解决方案

According to the apache mailing list, you can just directly write to /dev/stdio (on Unix like systems) as that's just a regular ol' file handle. Easy! Pasting...

The most efficient answer depends on your operating system. If you're on a UNIX like system which provides /dev/stdout and /dev/stderr (or perhaps /dev/fd/1 and /dev/fd/2) then use those file names. If that isn't an option use the piped output feature. For example, from my config:

CustomLog "|/usr/sbin/rotatelogs -c -f -l -L /private/var/log/apache2/test-access.log /private/var/log/apache2/test-access.log.%Y-%m-%d 86400 " krader_custom ErrorLog "|/usr/sbin/rotatelogs -c -f -l -L /private/var/log/apache2/test-error.log /private/var/log/apache2/test-error.log.%Y-%m-%d 86400"

Obviously you'll want to substitute another program for /usr/sbin/rotatelogs in the example above that writes the data where you want it to go.

https://mail-archives.apache.org/mod_mbox/httpd-users/201508.mbox/%3CCABx2=D-wdd8FYLkHMqiNOKmOaNYb-tAOB-AsSEf2p=ctd6sMdg@mail.gmail.com%3E

这篇关于如何在Docker容器中使用Apache,并且什么都不写入磁盘(所有日志到STDIO / STDERR)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆