Docker Community Forums

Share and learn in the Docker community.

Apache2 logging to 2 locations

I am using a PHP / Apache2 container for my site. The image is based off:


This has the following Dockerfile config to redirect log files to the docker host, using STDOUT & STDERR:

# logs should go to stdout / stderr
RUN set -ex \
&& ln -sfT /dev/stderr "$APACHE_LOG_DIR/error.log" \
&& ln -sfT /dev/stdout "$APACHE_LOG_DIR/access.log" \
&& ln -sfT /dev/stdout "$APACHE_LOG_DIR/other_vhosts_access.log"

I would like to use GoAccess for log analytics. This has a predefined formatters for apache and nginx that I would like to use.

From research, people who are using GoAccess with Docker are mounting a data volume to the container so the log files are actually stored on the Docker host’s filesystem. Currently, this presents 2 problems:

1 - Dynamically locating Docker’s log file location, particularly when a container respawns itself. This page describes a technique for doing it.
2 - But this file is in JSON format, which means I now need to use a customised GoAccess template / config file.

My initial thoughts are to restore the original apache2 log files. Can I duplicate the logging to both the original apache2 log file location (/var/log/apache2/access.log) and use Docker Logging API? Or is there another technique to solve this problem?

I don’t actually need “real time” analysis, but I would like to ensure that the full logs are retained. For example, if the container restarts, I may only retain the log file for the most recent container instance. And I would like to retain the use of Docker’s Logging as its handy to use with Portainer to manage my container instances and quickly troubleshoot.

Lastly, how do I go about customising GoAccess to use the Docker Logging API format? I have only just found this software and it doesn’t look trivial to change without understanding…

Hi Danburt,

you could create an additional apache log file. A file equivalent to the access log. This log file then could be mounted as volume between httpd container and host. See this link for string format and log file documentation:

The mounted file also needs to be specified as volume to the goaccess container. I’ll try and build an example. I’d post it here when I have a working example.