How does one use Apache in a Docker Container and write nothing to disk (all logs to STDIO / STDERR)?

I'm not positive that this won't mess with httpd's logging at all (e.g. if it tries to seek within the file), but you can set up symlinks from the log paths to /dev/stdout and /dev/stderr, like so:

ln -sf /dev/stdout /path/to/access.log
ln -sf /dev/stderr /path/to/error.log

The entry command to the vanilla httpd container from Docker Hub could be made to be something like

ln -sf /dev/stdout /path/to/access.log && ln -sf /dev/stderr /path/to/error.log && /path/to/httpd

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


I know it's an old question, but I had this need today.

On an Alpine 3.6, the following instructions, in httpd.conf, are working:

Errorlog /dev/stderr
Transferlog /dev/stdout

I add them to my container this way:

FROM alpine:3.6
RUN apk --update add apache2
RUN sed -i -r 's@Errorlog .*@Errorlog /dev/stderr@i' /etc/apache2/httpd.conf
RUN echo "Transferlog /dev/stdout" >> /etc/apache2/httpd.conf
...