I have an Apache container (image: httpd:2.4
) that I am using in a docker-compose arrangement. I am trying to store the logs on the host so that I can analyze them using AWStats.
To accomplish this, I put the following line in my docker-compose.yml
file:
volumes:
# log files
- /path/on/host/apache_logs:/var/log/apache2
And I can see both access.log
and error.log
in the folder on the host just fine.
The problem is that not all requests are showing up in access.log
.
If I inspect the logs on the container (eg. docker logs ...
), I can see the log entries for the requests I made (the ones that I was hoping to see in access.log
).
Why is there a difference between the two?
And, more importantly, what is the correct approach to get the Apache container to record their logs in a directory that's available on the host?
Update
Based on the comment by @DavidMaze, I can see that the Apache image is configured to send the logs to stdout. So, one solution I am attempting is to just transfer the logs to a file on the host once a day in a cron job based on this answer.
This seems to work okay, but I'm seeing duplicate entries in the log. It's the same data just re-arranged in different formats.
For example, the first line will be in the order of remote host (%h
), (%l
), userid (%u
), time (%t
), and then request (%r
). And then the second line will be: %t %h
, followed by some TLS information (eg. TLSv1.3
), and then %r
.
The first line is my preferred format (since it obeys the common
format from Apache and can be understood by AWStats).
Is there a way to configure docker or Apache to just stick to printing the first line?