Skip to content
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

php:8.2-fpm (bullseye) docker (swarm) no log #1411

Open
peterschristoph opened this issue May 30, 2023 · 8 comments
Open

php:8.2-fpm (bullseye) docker (swarm) no log #1411

peterschristoph opened this issue May 30, 2023 · 8 comments

Comments

@peterschristoph
Copy link

peterschristoph commented May 30, 2023

hi, after some time i am convinced that there is a bug in php:8.2-fpm image or in connection with docker swarm or in docker?

When using the php:8.2-fpm image, this repo writes a docker config which redirects the access and error log to the proc self fd 2. Unfortunately all logs that should end up in the docker logs are lost.

Environment

  • Docker version 24.0.2, build cb74dfc
  • Dockerhost: Ubuntu 22 LTS
  • Image: php:8.2-fpm

further information

# cat local/etc/php-fpm.d/docker.conf
[global]
error_log = /proc/self/fd/2

; https://github.com/docker-library/php/pull/725#issuecomment-443540114
log_limit = 8192

[www]
; php-fpm closes STDOUT on startup, so sending logs to /proc/self/fd/1 does not work.
; https://bugs.php.net/bug.php?id=73886
access.log = /proc/self/fd/2

clear_env = no

; Ensure worker stdout and stderr are sent to the main error log.
catch_workers_output = yes
decorate_workers_output = no

Inside docker container:

# ls -la /proc/self/fd/2
lrwx------ 1 root root 64 May 30 09:43 /proc/self/fd/2 -> /dev/pts/0
# ls -la /proc/self/fd/1
lrwx------ 1 root root 64 May 30 09:44 /proc/self/fd/1 -> /dev/pts/0
# ls -la /proc/1/fd/2
l-wx------ 1 root root 64 May 30 01:33 /proc/1/fd/2 -> 'pipe:[1118282]'
# ls -la /dev/stderr
lrwxrwxrwx 1 root root 15 May 30 01:33 /dev/stderr -> /proc/self/fd/2
  • /dev/stderr --> PARTLY WORKING (only from php, not in bash/sh)
  • /proc/self/fd/2 --> NOT WORKING
  • /proc/1/fd/2 --> WORKING
  • some file in mount --> WORKING

I'm not the only one with this behavior, for example: #878 (comment)

@peterschristoph peterschristoph changed the title php-fpm:8.2 (bullseye) docker (swarm) no log php:8.2-fpm (bullseye) docker (swarm) no log May 30, 2023
@iotanum
Copy link

iotanum commented Sep 19, 2023

Having the same issue. Haven't found a solution atm.
Running 8.2-php-fpm in K8S, neither /proc/self/fd/2 nor /proc/1/fd/2 work for me.

@Ziyann
Copy link

Ziyann commented Dec 12, 2023

I'm also having this issue, with the 8.2-fpm-alpine3.18 images.
Dockerfile writes the error_log directive to /usr/local/etc/php-fpm.d/docker.conf.
However, phpinfo reveals that that file isn't parsed.

@LaurentGoderre
Copy link
Member

I think it's normal that only /proc/1/fd/2 works because it's the output of process number 1. Using self would refer to another process when running it from a shell.

@LaurentGoderre
Copy link
Member

Maybe this part of the Dockerfile is relevant:

https://github.com/docker-library/php/blob/master/8.3/bookworm/fpm/Dockerfile#L271-L272

@renepupil
Copy link

renepupil commented Apr 9, 2024

For anyone who wants to log to kubernetes stdout:

As stupid as it may look putting the php-fpm command in a bash script from a docker file logs properly:

RUN touch /start.sh
RUN echo "#!/bin/bash" >> /start.sh
RUN echo "php-fpm" >> /start.sh
...
CMD ["/bin/bash", "/start.sh"]

EDIT: As suggested by @yosifkit not recommended

CMD ["/bin/bash", "-c", "tail -f /var/logs/some/error.log & php-fpm"]
# tail => Utility for displaying the last part of files.
#   -f => Keep the file open after reaching the end and continuously monitors the file, output new content to stdout.

Sry, but found this issue when searching for that problem...

@yosifkit
Copy link
Member

yosifkit commented Apr 9, 2024

CMD ["/bin/bash", "-c", "tail -f /var/logs/some/error.log & php-fpm"]

I would strongly suggest caution before using this. This leaves bash as a resident process and so any signal (like SIGINT/SIGHUP) would be sent to bash (and ignored, since it is PID 1) and not to the PHP process. So, stopping the container would not work without SIGKILL (or manually signaling the PHP process inside the container).

@renepupil
Copy link

renepupil commented Apr 11, 2024

@yosifkit Hey, thanks for your feedback, just a few questions regarding that...

So, docker stop or stopping the container via Docker desktop would not work, right? (We had to use kill)

Just tested this using the image with tail -f /var/logs/some/error.log as a kubernetes container image, and it seems at least kubernetes does not have problem replacing the pod when the resource gets updated.

Do you know any other problems that might occur using that workaround in kubernetes?

@renepupil
Copy link

I found another working solution:

RUN touch /start.sh
RUN echo "#!/bin/bash" >> /start.sh
RUN echo "php-fpm" >> /start.sh
...
CMD ["/bin/bash", "/start.sh"]

@yosifkit Do you see any issues with that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants