2017-05-30 52 views
0

我正在運行一個php docker鏡像(php:5.6-apache),它使用符號鏈接分別將apache的錯誤和訪問日誌重定向到STDERR和STDOUT。無法看到碼頭的STDERR輸出

當我在前臺運行docker鏡像或訪問docker容器日誌時,可以看到STDOUT輸出。但我沒有看到任何錯誤(即使當我生成php錯誤)。

任何想法,爲什麼這是我該如何解決它?

我正在爲Mac泊塢窗(但我不認爲這有什麼差別)

感謝

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

編輯/解決: 作爲@BMitch提到以下證明, STDERR重定向工作正常。 問題出在PHP配置上。如果我用error_log()記錄了一個錯誤,它會輸出到日誌。但是,如果我有一個PHP錯誤,如調用未定義的函數,錯誤將永遠不會出現在日誌中。這似乎有點不一致。在任何情況下,...

我曾在/usr/local/etc/php/創建php.ini文件並添加這兩個參數:

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

,然後重新啓動泊塢窗容器。這導致所有PHP錯誤被記錄並輸出到STDERR。請參閱@德語的答案爲例。

+0

你安裝的卷? – BMitch

+0

@BMitch,是的,但只有/ var/www – swbandit

回答

2

我無法重現您的情況。如果以下內容無效,請提供您的錯誤mcve

基本Dockerfile:

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

唯一的PHP是該文件生成一個錯誤:

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

生成並運行它:

$ 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 localhost:8080/error.php 

顯示標準輸出日誌,重定向錯誤到/ 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" 

顯示標準錯誤日誌重定向標準輸出到/ 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. 

注意錯誤輸出的最後一行。

+0

是的,如果你直接調用'error_log()',它似乎工作。但是,如果調用'error_pug()'(當然不存在),日誌不會顯示任何錯誤。您只會在瀏覽器中看到錯誤。 – swbandit

+0

今天早上我正在與此戰鬥,但耗盡時間。我相信php.ini需要更新,但我無法應用我的更改(可能爲5.6版本編寫了錯誤的文件)。這個問題在php方面更詳細:https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display – BMitch

3

如果你想看到apache2日誌中的php錯誤,你必須激活它們。爲此,您必須將php.ini文件寫入/ usr/local/etc/php文件夾中。

我在存儲庫中編寫了一個示例,以便可以看到該示例。

https://github.com/nitzap/stackoverflow-docker-php-error-log

如果你想看到的輸出和錯誤日誌,你可以用下面的命令做到這一點,你的容器外:

docker logs <name_container> 

現在,如果你想在保持連接日誌中可以像在tail命令中那樣添加-f選項。

docker logs <name_container> -f