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条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP