0

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?

rumski20
  • 361
  • 4
  • 13
  • The default image setup looks like it [sends most logs to stdout and stderr](https://github.com/docker-library/httpd/blob/a7acc047c8970e0502f4c6b577775f840f1f99b6/2.4/Dockerfile#L205-L207) so they show up in the `docker logs` output; log collectors like fluentd know how to read that. Is the default Docker logging setup enough for you here? – David Maze Dec 31 '21 at 20:58
  • @DavidMaze - Given what you said, it's interesting that anything shows up in `access.log` on the host at all. I would be fine with the default Docker logging as long as I can write those logs to a file on the host. I use another container (outside of this docker-compose setup) to analyze these logs using AWStats. I am not familiar with fluentd. – rumski20 Dec 31 '21 at 21:06

0 Answers0