I am using a PHP / Apache2 container for my site. The image is based off:
php:7.2-apache
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 \
&& . "$APACHE_ENVVARS" \
&& 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…