dsc6517 2017-05-30 05:25
浏览 1352
已采纳

无法使用docker查看STDERR输出

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.

  • 写回答

3条回答 默认 最新

  • duan0417 2017-05-31 00:11
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺