Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Unable to see messages logged to STDERR in docker logs #592

Closed
siddjain opened this issue Mar 23, 2021 · 4 comments
Closed

Unable to see messages logged to STDERR in docker logs #592

siddjain opened this issue Mar 23, 2021 · 4 comments

Comments

@siddjain
Copy link

siddjain commented Mar 23, 2021

We are using the wordpress:php7.4-fpm-alpine image. We are logging to STDERR using following as example:

error_log($msg, 3, '/dev/stderr');

but do not see the message in Docker logs. If we replace /dev/stderr with a local filename such as /var/www/html/wp-debug.log the message does appear there.

Things we tried (none of which worked):

  • replace /dev/stderr with /proc/self/fd/2
  • replace /dev/stderr with /proc/1/fd/2

we have verified catch_workers_output is set to yes in /usr/local/etc/php-fpm.d/docker.conf.

below are the different kinds of error messages in wordpress logs:

[23-Mar-2021 18:48:55 UTC] PHP Warning:  error_log(/dev/stderr): failed to open stream: No such file or directory in /var/www/html/wp-content/logging.php on line 11
[23-Mar-2021 20:26:06 UTC] PHP Warning:  error_log(/proc/1/fd/2): failed to open stream: Permission denied in /var/www/html/wp-content/logging.php on line 11
[23-Mar-2021 21:13:15 UTC] PHP Warning:  error_log(/proc/self/fd/2): failed to open stream: No such file or directory in /var/www/html/wp-content/logging.php on line 11

the /dev/stderr does clearly exist:

bash-5.0# ls -al /dev/stderr
lrwxrwxrwx    1 root     root            15 Mar 23 20:04 /dev/stderr -> /proc/self/fd/2
bash-5.0# ls -al /proc/self/fd/2
lrwx------    1 root     root            64 Mar 23 21:18 /proc/self/fd/2 -> /dev/pts/0
bash-5.0# ls -al /dev/pts/0
crw--w----    1 root     tty       136,   0 Mar 23 21:18 /dev/pts/0
@wglambert
Copy link

The /proc/1/fd/2 should be the stderr of PID 1 so anything written there should then output in docker log
docker-library/php#811 (comment)

I think the error_log(/proc/self/fd/2): failed to open stream: No such file or directory is because /proc/self/fd/ is redirected to /dev/pts/0 which only exists when you're "attached" to the container (with docker exec -it)

@siddjain
Copy link
Author

So what's the solution here? Is there something that can be done to prevent permission denied when trying to open /proc/1/fd/2? Can one chmod this file? is it safe?

bash-5.0# ls -al /proc/1/fd/2
l-wx------    1 root     root            64 Mar 23 20:04 /proc/1/fd/2 -> pipe:[33197]

@siddjain
Copy link
Author

this answer has 28 upvotes and says to set:

access.log = /proc/self/fd/2
error_log = /proc/self/fd/2

which is also the setting in /usr/local/etc/php-fpm.d/docker.conf that comes with the Docker image. But logging to this doesn't work...

@tianon
Copy link
Member

tianon commented Mar 23, 2021

I think the conclusion in docker-library/php#878 is that this is complicated and often doesn't work at all -- I don't think anyone's found a good generally applicable workaround for it.

@docker-library docker-library locked and limited conversation to collaborators Mar 26, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants