I am trying to get the error logs out of my php docker. I found that the error.log file was going nowhere, hence modified my dockerfile like this:
FROM php:7.4-apache
RUN a2enmod rewrite
RUN docker-php-ext-install mysqli pdo pdo_mysql; \
docker-php-ext-enable mysqli pdo pdo_mysql;
# Redirect apache log files to stdout, see https://github.com/moby/moby/issues/19616
RUN ln -sf /proc/1/fd/1 /var/log/apache2/access.log
RUN ln -sf /proc/1/fd/1 /var/log/apache2/error.log
Resulting in the files below:
# ls -l /var/log/apache2/
total 0
lrwxrwxrwx 1 root root 12 May 11 18:25 access.log -> /proc/1/fd/1
lrwxrwxrwx 1 root root 12 May 11 18:25 error.log -> /proc/1/fd/1
lrwxrwxrwx 1 www-data www-data 11 Nov 15 04:17 other_vhosts_access.log -> /dev/stdout
That part is now working: running echo "test" > /var/log/apache2/error.log
does write test to the docker logs. Plus, file permissions are not restrictive (see https://stackoverflow.com/a/12566881/3519951).
I added a crashing call, dfgdfga.test()
, but the error doesn't show up. Same if I create a log file instead of redirecting to docker output. It remains empty.