Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to see STDERR Output with docker

I'm running a php docker image (php:5.6-apache) which has apache's error and access logs redirected to STDERR and STDOUT respectively using symbolic links.

When I run the docker image in the foreground or access the docker container logs, I can see the STDOUT output. But I don't see any errors (even when I generate php errors).

Any idea why that is and how I can fix it?

I'm running docker for Mac (but I don't think this makes any difference)

Thanks

access.log -> /dev/stdout
error.log -> /dev/stderr
other_vhosts_access.log -> /dev/stdout

Edit / Solved: As @BMitch mentions and proves below, the STDERR redirection works fine. The problem was with PHP configuration. If I logged an error with error_log(), it would get output to the log. But if I had a php error, like calling an undefined function, the error would never appear in the log. This seems a little inconsistent. In any case, ...

I had to create a php.ini file in /usr/local/etc/php/ and add these two parameters:

log_errors = On
error_log = /var/log/apache2/error.log

and then restart the docker container. This caused all PHP errors to be logged and output to STDERR. See @German's answer for an example.

like image 754
swbandit Avatar asked May 30 '17 05:05

swbandit


People also ask

Does docker logs show stderr?

By default, docker logs shows the command's STDOUT and STDERR .

Where are the docker daemon logs?

The Docker daemon log can be viewed by using one of the following methods: By running journalctl -u docker. service on Linux systems using systemctl. /var/log/messages , /var/log/daemon.

How do I view docker crash logs?

You find these JSON log files in the /var/lib/docker/containers/ directory on a Linux Docker host. The <container_id> here is the id of the running container.


1 Answers

I'm unable to reproduce your situation. If the below doesn't help, please provide an mcve of your error.

Basic Dockerfile:

$ cat Dockerfile 
FROM php:5.6-apache
COPY . /var/www/html/

The only php is this file to generate an error:

$ cat error.php 
<?
error_log("Hello error log.")
?>

Build and run it:

$ docker build -t test-php .
Sending build context to Docker daemon  3.072kB
Step 1/2 : FROM php:5.6-apache
 ---> f16436448ebd
Step 2/2 : COPY . /var/www/html/
 ---> Using cache
 ---> cfe66485e2cc
Successfully built cfe66485e2cc
Successfully tagged test-php:latest

$ docker run -p 8080:80 -d --name test-php test-php
7f9a1836a8157963966b583579dff94c6413292547b84d22957add77ad2d8e14

Curl is empty as expected, but calling it generates an error in the logs:

$ curl localhost:8080/error.php

Show stdout logs, redirecting error to /dev/null:

$ docker logs test-php 2>/dev/null
172.17.0.1 - - [31/May/2017:00:06:37 +0000] "GET /error.php HTTP/1.1" 200 174 "-" "curl/7.38.0"

Show stderr logs, redirecting stdout to /dev/null

$ docker logs test-php >/dev/null
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
[Wed May 31 00:06:25.064546 2017] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/5.6.30 configured -- resuming normal operations
[Wed May 31 00:06:25.064584 2017] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
[Wed May 31 00:06:37.833470 2017] [:error] [pid 17] [client 172.17.0.1:50040] Hello error log.

Note the last line of the error output.

like image 199
BMitch Avatar answered Oct 18 '22 11:10

BMitch