Hi,
I need some advice from more seasoned docker users.
I am extending the official php-image in my Dockerfile like this:
FROM php:5.6-apache
MAINTAINER "John Doe <[email protected]>"
COPY ./templates/apache2files/piwik /var/www/html/
COPY ./templates/php.ini /usr/local/etc/php/
RUN chmod 777 -R /var/www/html/
RUN docker-php-ext-install mysqli
RUN docker-php-ext-install mbstring
I build the dockerfile with this:
docker build -t mypiwik
I run the container like this:
docker run -d --name mypiwikcontainer -p "8888:80" mypiwik:latest
I can see the access.log using this:
docker logs mypiwikcontainer
How can I see the error.log?????
Hi,
What have you got in your logs? (docker logs mypiwikcontainer)
Currently I have the following (version 7.0-apache):
[core:warn] [pid 1] AH00111: Config variable ${APACHE_RUN_DIR} is not defined
Therefore, there might be no file, unless I actually set this variable (currently investigation).
Also, you do not need to access the file. You can probably read it by connecting with ssh (docker exec -it mypiwikcontainer /bin/bash), and then access the right directory and use less or whatever is installed. I would personally use docker logs and am trying to get into the log drivers to centralise logs to a central graylog instance.
@keltik85
I had the same issue and solved it the following way:
In your php.ini, add the following lines:
log_errors = On
error_log = /dev/stderr
Now you'll be able to see any PHP error logs as part of the docker container log stream:
docker logs -f your_php_apache_container
To display only errors and hide the access log, you can pipe stdout to /dev/null:
docker logs -f your_php_apache_container >/dev/null
To follow only the access log, you can pipe stderr to /dev/null:
docker logs -f your_php_apache_container 2>/dev/null
It's cool, but how to get actual log files?
check that 000-default site is enabled for your apache,
in my case /etc/apache2/sites-enabled/ does not contained softlink to 000-default.conf
so I ran
a2ensite 000-default
apache2ctl restart
then i started seeing logs in access.log and error.log
@povils Container apps shouldn't write log files in the container, as its lifecycle is meant to be "disposable", unless you mount a volume and want them on your file system. This is a core tenet of the 12-factor-app methodology.
If you docker exec -it app-name ls -alh /var/log/apache2/ you will see the log files are symlinked to /dev/stderr and /dev/stdout as they should. This allows the container engine to expose logs via the docker logs -f app-name command or an orchestrator like Swarm or Kubernetes to expose them to centralized logging like ELK stack or Stackdriver.
@mikesparr Thanks for the answer. I needed log files because I am using Elastic Filebeat which harvests log files and streams that to our ELK
I believe you enable fluentd and configure logging output. The ephemeral nature of containers is meant to stream logs not write them so you need to capture the stream one layer up, then ship em.
Sent from my iPhone
On Oct 20, 2017, at 2:51 AM, Povilas Susinskas notifications@github.com wrote:
@mikesparr Thanks for the answer. I needed log files because I am using Elastic Filebeat which harvests log files and streams that to our ELK
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
@blueimp thanks, works perfectly! I wonder, why isn't it included into default PHP Docker image....
I solved this problem adding next command in dockerfile
RUN cp $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini
Most helpful comment
@keltik85
I had the same issue and solved it the following way:
In your
php.ini, add the following lines:Now you'll be able to see any PHP error logs as part of the docker container log stream:
To display only errors and hide the access log, you can pipe
stdoutto/dev/null:To follow only the access log, you can pipe
stderrto/dev/null: