Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm running Apache2 in a docker container and want to write nothing to the disk, writing logs to stdout and stderr. I've seen a few different ways to do this (Supervisord and stdout/stderr, Apache access log to stdout) but these seem like hacks. Is there no way to do this by default?

To be clear, I do not want to tail the log, since that will result in things being written to the disk in the container.

The "official" version checked into Docker Hub (https://hub.docker.com/_/httpd/) still write to disk.

Also, what do I need to do to stop Apache from failing when it tries to roll the logs?

One other thing - ideally, I'd really like to do this without another add-on. nginx can do this trivially.

like image 401
aronchick Avatar asked Aug 13 '15 22:08

aronchick


People also ask

How do I run Apache docker?

To run an Apache httpd Docker container with a volume mapping that points to the local file system, simply issue a docker run command with these attributes: The -d switch to run the process as a daemon. The --name switch to provide a friendly name for the container. Mapping port 80 to an open port on your machine.

Where are docker logs written?

You find these JSON log files in the /var/lib/docker/containers/ directory on a Linux Docker host.

Where are docker logs stored on disk?

The default logging driver as I mentioned above is a JSON file located on the local disk of your Docker host: /var/lib/docker/containers/[container-id]/[container-id]-json. log.


1 Answers

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
like image 51
Alex Robinson Avatar answered Sep 25 '22 09:09

Alex Robinson