如何配置在docker容器中运行的Apache同时记录文件和控制台?

时间:2015-12-20 14:06:24

标签: apache logging docker

我有一个运行Apache的docker容器。我希望Apache将日志保存到文件系统(分别访问和错误日​​志以及滚动)。另外,我希望看到带有docker logs命令的实时日志。

如何配置在docker容器中运行的Apache同时记录文件和控制台?

1 个答案:

答案 0 :(得分:1)

您需要使用tee命令管道到Apache进程的标准输出流(/proc/1/fd/1)和rotatelogs,如下所示:

CustomLog "|$/usr/bin/tee -a /proc/1/fd/1 | bin/rotatelogs -l -n 30 logs/access.log 10M" common
# Apache captures stderr itself and pipes it to itself. As this would make an infinite loop, we use stdout here for Docker (/prod/1/df/1)
ErrorLog "|$/usr/bin/tee -a /proc/1/fd/1 | bin/rotatelogs -l -n 10 logs/error.log 2M"