Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where is the error.log? #212

Closed
keltik85 opened this issue Apr 1, 2016 · 10 comments
Closed

Where is the error.log? #212

keltik85 opened this issue Apr 1, 2016 · 10 comments

Comments

@keltik85
Copy link

keltik85 commented Apr 1, 2016

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 <Johndoe@dough.com>"
        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?????

@tdutrion
Copy link

tdutrion commented Apr 1, 2016

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.

@blueimp
Copy link

blueimp commented Apr 2, 2016

@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

@keltik85 keltik85 closed this as completed Apr 5, 2016
@povils
Copy link

povils commented May 17, 2017

It's cool, but how to get actual log files?

@Raaghu
Copy link

Raaghu commented May 29, 2017

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

@mikesparr
Copy link

@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.

@povils
Copy link

povils commented Oct 20, 2017

@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

@mikesparr
Copy link

mikesparr commented Oct 20, 2017 via email

@okainov
Copy link

okainov commented May 11, 2019

@blueimp thanks, works perfectly! I wonder, why isn't it included into default PHP Docker image....

@buster95
Copy link

I solved this problem adding next command in dockerfile

RUN cp $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini

@Videles
Copy link

Videles commented Apr 26, 2022

@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

This works like a charms, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants